Consulting

Results 1 to 2 of 2

Thread: Setting value of formfield

  1. #1

    Setting value of formfield

    Hi,

    I am using VBA to open a from from another form. The Code to open the form is as follows:
    [VBA]
    Private Sub txtDayBlock04_DblClick(Cancel As Integer)
    tempDate = CDate(Me![txtDayBlock04].Tag)
    DoCmd.OpenForm "frmPatients", acNormal, , "[Date] = #" & CDate(Me![txtDayBlock04].Tag) & "#"
    End Sub
    [/VBA]

    tempDate is a Public Var Dim'd in a Module

    The Form_Load Event reads:

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

    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

  2. #2
    The answer is to set the Default Value for the textbox control on the subsequent form.


    [VBA]Private Sub Form_Load()
    Me.Date.DefaultValue = CDate(tempDate)
    End Sub[/VBA]

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •