Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default date value from a Calendar

Status
Not open for further replies.

jaanisf

Technical User
Apr 30, 2003
50
LV
I need to add many records with the same date in my form. So I put a button next to my date text box "dat", that wakes up a calendar. That looks like this:

Calendar.Visible = True
Calendar.SetFocus

Then I put a following code:

Private Sub Calendar_Click()
Me!dat.DefaultValue = "#" & Calendar.Value & "#"
Combo18.SetFocus
Calendar.Visible = False
End Sub

Where Combo18 is the next box below date text box.

I tried also:
Me!dat.DefaultValue = Calendar.Value
and Me.dat.DefaultValue = Calendar.Value
and Me.dat.DefaultValue = "#" & Calendar.Value & "#"

That all leads to a #Name? in my date text box "dat".
Can you help me, please, with this?
 
I haven't tested, but I'd expect

dat = Calendar.Value

to work.

It really isn't a default value if a user has to do something to update it. A default value would be the value that is inserted as soon as a new record is created. You could set the default value to Now() on the property window for the textbox and then use your code to change it if necessary.

HTH
 
Then this should work:

Private Sub Calendar_Click()
dat = Calendar.Value
Me.dat.DefaultValue = "#" & Calendar.Value & "#"
Combo18.SetFocus
Calendar.Visible = False
End Sub

But it works for the current record only. When I it jumps to next new record, it shows #Name? again.
 
It shows the right value in properties and still there's a #Name? in text box.
Maybe there is another way out? For example, can I take the last records date as a default value?
 
It seems I found it. As the Caloendar allways stays on the last chosen date, all I should do is to put [Calendar].[Value] in default value field in textt box properties. Now it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top