#1
|
|||
|
|||
Return Value from DTpicker into DocVariable in Word
Hello there..
I have several Comboboxes and Textboxes in my UserForm all of them are returning correctly into my DocVariables. The code I used to return Textbox Value to the Variable is: ActiveDocument.Variable("var1") = Textbox1.value I tried now to do the same with the DTPicker ActiveDocument.Variable("var2") = DTPicker.value But it returns either 00:00:00 or 30 0000 2015. I tried to format the DTPicker with the code: DTPicker = Format(DTPicker,"dd mmmm yyyy") Also I tried to change the Variable to: {DocVariable var2 \@ "dd mmmm yyyy"} Each way didn't work. So please can somebody help me. |
#2
|
||||
|
||||
Code:
ActiveDocument.Variables("varDate").Value = Me.DTPicker1.Value Code:
ActiveDocument.Variables("varDate").Value = Format(Me.DTPicker1.Value, "Long Date")
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
with your help i got now a date what looks like a date.
But it shows now "Saturday, 30. December 1899" As I understood this means the DTPicker value is 0 means something doesn't work. may you help me again? |
#4
|
||||
|
||||
I notice that your message header indicates Office 2010 64 bit. I have no idea to what extent the 64 bit version will work correctly with DTPicker (if at all).
Did you set the initial value of the picker e.g. Code:
Me.DTPicker1.Value = Date
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
yes I initialized the date.
What is weird ist that in my document (whit several textboxes an comboboxes) where I actually need the datepicker it doesn't work. But when I Open a new blank document and make a userform with just a datepicker and a docvariable it works only with the code: activedocument.variables("var2").Value = DTPicker1.Value |
#6
|
|||
|
|||
After a few researches I finally got the todays date shown as I want it. But when I run the userform and change the date it doesn't update in my docvariable.
But i have the code as above: ActiveDocument.Variables("varDate").Value = Format(Me.DTPicker1.Value, "Long Date") Does somebody know a solution that the date choosen in the userform is in my docvariable? |
#7
|
||||
|
||||
Most Word fields do not automatically update. Add code to update the field(s)
The example code in http://www.gmayor.com/installing_macro.htm will update all the fields in the document (including the docvariable fields). Call it from your macro.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#8
|
|||
|
|||
thank you for your help. But I already have the code to update all.
I now figured out that when I do "me.hide" the userform it works but it doesn't work when I do "unload me". I would prefer to have the "unload me" solution. Do you know why it makes a difference between unload and hide? |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
DocProperty vs DocVariable | ChrisBrewster | Word VBA | 1 | 02-07-2014 02:09 PM |
DocVariable formatting and the ability to truncate a string. | MaxInCO | Word | 1 | 12-18-2013 05:35 PM |
Calculate the coordinates of a DocVariable, Bookmark or paragraph. | MaxInCO | Word VBA | 5 | 12-11-2013 03:28 PM |
DTPicker date formatting | Andy2011 | Word VBA | 1 | 08-24-2012 02:45 PM |
DOCVARIABLE copy paste special | cyndor | Word | 2 | 04-06-2012 03:57 AM |