UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Need Help With A Button To Run After Update Event On A Subform, Access 2013    
 
   
slowpoke
post Oct 11 2019, 10:04 PM
Post#1



Posts: 26
Joined: 15-April 19



Hi there...

I need help but not quite sure how to start. If anyone can help with examples, that would be great.

Here's my problem...

I have a subform, in it contains many rows of info. I need to place a button on the main form to run the after update event in the subform.

The field in the subform is called SOMEFIELD.

Me.SOMEFIELD_AfterUpdate

Can anyone point me in the direction on what to do? I know it requires recordset to test if there is data, then execute the event, looping until the last data record, just not sure how to go about it hence some examples would be great.

As always... appreciate you steering me in the right direction. Thanks.
Go to the top of the page
 
theDBguy
post Oct 11 2019, 10:06 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,644
Joined: 19-June 07
From: SunnySandyEggo


Hi. Depending on what the AfterUpdate code does, it might be simpler just to duplicate it. To be sure, can you please post the code you're trying to run? Thanks.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
arnelgp
post Oct 11 2019, 11:17 PM
Post#3



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


on the Click event of your button in Main form:
CODE
Private Sub button_Click()
    With Me.subformName.Form.RecordsetClone
        If Not (.BOF And .EOF) Then .MoveFirst
        While Not .EOF
            If !SOMEFIELD  ([ = | <> ] the condition here) Then
                .Edit
                'update which field
                .Update
            End If
            .MoveNext
        Wend
    End With
End Sub

This post has been edited by arnelgp: Oct 11 2019, 11:18 PM

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
slowpoke
post Oct 12 2019, 10:23 AM
Post#4



Posts: 26
Joined: 15-April 19



Thanks for pointing me in the right direction. I almost got it working except...

I now have a button the main form with the following code:

Private Sub header_single_test_function_Click()

With Me.dbo_crewtime.Form.RecordsetClone
If Not (.BOF And .EOF) Then .MoveFirst
While Not .EOF
If Not Nz(cbo_crewmember) Then
Me.dbo_crewtime.Form.cbo_crewmember_AfterUpdate
[Forms]![dbo_crew_timesheet].[dbo_crewtime].Form.Dirty = False

End If
.MoveNext
Wend
End With

End Sub


THE PROBLEM:

The code will update the first ROW in the subform and stop there even though I have multiple rows of data after the first row. Any idea what is causing the vba code not to move to the next row?

As always... thanks for everyone's guidance.





Go to the top of the page
 
arnelgp
post Oct 12 2019, 10:41 AM
Post#5



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


what is the Field name on the subform you want to update?
what is the Value or control that will update that field?

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
slowpoke
post Oct 12 2019, 11:21 AM
Post#6



Posts: 26
Joined: 15-April 19



The field name is called: crewmember

I want to run the event_afterupdate code for each row (almost like a refresh).

Any idea why the code won't process to the next record?

Thanks for your help and guidance.
Go to the top of the page
 
arnelgp
post Oct 12 2019, 01:18 PM
Post#7



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


CODE
Private Sub header_single_test_function_Click()

    With Me.dbo_crewtime.Form.RecordsetClone
        If Not (.BOF And .EOF) Then .MoveFirst
        While Not .EOF
            If Not Nz([cbo_crewmember]) Then
                .Edit
                !crewmember = cbo_crewmember
                .Update
           End If
           .MoveNext
        Wend
    End With

End Sub


--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
slowpoke
post Oct 13 2019, 05:34 PM
Post#8



Posts: 26
Joined: 15-April 19



Hi.. I wanted to thank you for steering me in the right direction. Without your guidance, I don't think I would get to this spot.

I was able to get the following code working:

Dim rst_labour As DAO.Recordset
Set rst_labour = Me.dbo_crewtime.Form.Recordset

If Not (rst_labour.EOF And rst_labour.BOF) Then
[Forms]![dbo_crew_timesheet].[dbo_crewtime].SetFocus
rst_labour.MoveFirst
'step through the recordset creating a new row in the subform for each record
Do Until rst_labour.EOF = True
[Forms]![dbo_crew_timesheet].[dbo_crewtime].Form!cbo_crewmember.SetFocus
[Forms]![dbo_crew_timesheet].[dbo_crewtime].Form!cbo_crewmember = rst_labour![crewmember]
Me.dbo_crewtime.Form.cbo_crewmember_AfterUpdate
[Forms]![dbo_crew_timesheet].[dbo_crewtime].Form.Dirty = False
rst_labour.MoveNext
Loop

end If
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    22nd November 2019 - 09:11 PM