Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reproducing the User Updating Data in a Text Box

    What's the VBA method that would allow me to reproduce the user selecting the content of a text box on a form and press the Enter key?
    I've tried the code highlighted below but the Energia text box in the MG1Maz subform doesn't get updated.
    Basically I'd like the EnerOm2 function you see below to be triggered also for the day after the one selected in the calendar on the startup form of the attached mdb.

    Private Sub LETTUR_AfterUpdate()
    If Me.NewRecord Then Giorno = Me.Parent.Form.CGior
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], Me!LETTUR, Me!LETTUR1)
    Me.Refresh
    <span style="background-color: #FFFF00; color: #000000; font-weight: bold">Me.Parent.Form.CGior = Me.Parent.Form.CGior + 1
    Me.LETTUR.SetFocus
    DoCmd.Requery</span hi>
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reproducing the User Updating Data in a Text Box

    Try

    Private Sub LETTUR_AfterUpdate()
    If Me.NewRecord Then Giorno = Me.Parent.Form.CGior
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], _
    Me!LETTUR, Me!LETTUR1)
    Me.Parent.Form.CGior = Me.Parent.Form.CGior + 1
    Me.Parent.CGior_AfterUpdate
    Me.LETTUR.SetFocus
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], _
    Me!LETTUR, Me!LETTUR1)
    End Sub

    You must make CGior_AfterUpdate public.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reproducing the User Updating Data in a Text Box

    Thank you so much Hans, that's another piece of mastery on your part. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    I've modified it into
    <font color=red> <pre>Private Sub LETTUR_AfterUpdate()
    If Me.NewRecord Then
    Giorno = Me.Parent.Form.CGior
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], _
    Me!LETTUR, Me!LETTUR1)
    ElseIf Giorno = DMax("Giorno", "g1maz") Then
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], _
    Me!LETTUR, Me!LETTUR1)
    Exit Sub
    Else
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], _
    Me!LETTUR, Me!LETTUR1)
    Me.Parent.Form.CGior = Me.Parent.Form.CGior + 1
    Me.Parent.CGior_AfterUpdate
    Me.LETTUR.SetFocus
    Energia = EnerOm2("g1maz", "mazg1k", [Giorno], [ORE_MARC], _
    Me!LETTUR, Me!LETTUR1)
    Me.Parent.Form.CGior = Me.Parent.Form.CGior - 1
    Me.Parent.CGior_AfterUpdate
    Me.LETTUR.SetFocus
    End If
    End Sub</pre>

    </font color=red>
    so that I bypass triggering the second call to the EnerOm2 function if the date selected on the calendar is for a new record or the last day in the subform record source and I also get the focus back to the date on the calendar which the text box was originally filled in for.
    Actually the original mdb from which I've extracted the example for this thread has another main form with the same form/subform structure and so I've had to declare CGior_AfterUpdate public in that main form module as well, what amazes me is the fact that when I compile the project code I don't get any conflict warning messages. Could it be because the code for the subroutine is the same in both modules?
    <font color=448800> <pre>Public Sub CGior_AfterUpdate()
    Dim strFilter As String
    strFilter = "Giorno = #" & Format(Me.CGior, "mm/dd/yyyy") & "#"
    Me.Filter = strFilter
    Me.FilterOn = True
    Me.Cdata.DefaultValue = "#" & Format(Me.CGior, "mm/dd/yyyy") & "#"
    End Sub</pre>

    </font color=448800>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reproducing the User Updating Data in a Text Box

    There is no conflict because the line
    <code>
    Me.Parent.CGior_AfterUpdate
    </code>
    explicitly specifies which version of CGior_AfterUpdate must be executed: the one in the parent (main) form of the subform. If the line was merely
    <code>
    CGior_AfterUpdate
    </code>
    you might get an error message (I haven't actually tested that).

Posting Permissions

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