PDA

View Full Version : Setting value of formfield



toddbuckles
12-27-2010, 04:44 PM
Hi,

I am using VBA to open a from from another form. The Code to open the form is as follows:

Private Sub txtDayBlock04_DblClick(Cancel As Integer)
tempDate = CDate(Me![txtDayBlock04].Tag)
DoCmd.OpenForm "frmPatients", acNormal, , "[Date] = #" & CDate(Me![txtDayBlock04].Tag) & "#"
End Sub


tempDate is a Public Var Dim'd in a Module

The Form_Load Event reads:


Private Sub Form_Load()
[Date] = tempDate
End Sub


Problem is when the form loads, only the first instance of [Date] is set to the tempDate variable. If no record exists, then the new instance of [Date] is set to tempDate. The desired effect is any time the form loads, only a new instance (therefore a new record in the db) is set to tempDate.

Any ideas?

TIA VM
TB

toddbuckles
12-27-2010, 07:58 PM
The answer is to set the Default Value for the textbox control on the subsequent form.


Private Sub Form_Load()
Me.Date.DefaultValue = CDate(tempDate)
End Sub

Special thanks to koolsid (vbforums.com) and also to RuralGuy (from Accessforums.com) for collaborating on the answer.