Solved close form and return to previous form with new data and insert into previous form (1 Viewer)

Polopudding

New member
Local time
Today, 16:32
Joined
Jul 24, 2021
Messages
4
I´m a bit of a novice with VBA and I think I´m biting off more than I can chew. I am creating a bookings application. On the booking form I can look up members, however if member does not exist, the user presses "New Member", the new member form opens. They fill in all the data, post to the members table, On Form Close I want the new members data (Name and ID) to transfer across to the Booking form and populate the member field.
It would probably be easier just to close the Booking form if the member doesn´t exist, add a new member in the new members form, save data to the members table, close the form and open a fresh instance of the Booking form.
If there is a smoother way I would be interested to find out.
Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:32
Joined
Oct 29, 2018
Messages
21,359
Hi. If the first form is still open while the second one is, you should be able to refer to it using the Forms! syntax.

For example, to assign a member ID to the first form, you might use something like:
Code:
Forms!NameOfFirstForm.MemberID=Me.ID
 

Polopudding

New member
Local time
Today, 16:32
Joined
Jul 24, 2021
Messages
4
Thanks DBguy, No, it didn't work although it didn't cause an error either. When I return to the previous form (frmbooking) neither of my nominated fields are populated. I suspect that the form probably needs to refresh???? If I close the frmbooking and open it, search on members in the members combo box list my new entry is there as I expected but that's not really the result I was hoping to achieve.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:32
Joined
Oct 29, 2018
Messages
21,359
Thanks DBguy, No, it didn't work although it didn't cause an error either. When I return to the previous form (frmbooking) neither of my nominated fields are populated. I suspect that the form probably needs to refresh???? If I close the frmbooking and open it, search on members in the members combo box list my new entry is there as I expected but that's not really the result I was hoping to achieve.
Hi. Sorry to hear that. However, I can't tell you exactly why it didn't work, if I can't see what you're doing. Can you post the code you tried?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:32
Joined
May 7, 2009
Messages
19,175
on the "new member" form:
Code:
Dim thisID As Variant

Private Sub Form_BeforeUpdate(Cancel As Integer)
    thisID = Me.ID
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ' replace 'FirstForm with the correct name of form
    If Val(thisID & "") <> 0 Then
        With Forms!FirstForm
            .Requery
            .Recordset.FindFirst "id = " & thisID
        End With
    End If
End Sub
 

Polopudding

New member
Local time
Today, 16:32
Joined
Jul 24, 2021
Messages
4
Thank you to everybody who replied with suggestions for this issue. Thanks to fantastic @mike60smart and his excellent teaching skills who made me see the errors of my ways and point me in the right direction. I have learnt that the Wizards do a lot more than I had ever given them credit for. A bit more reading up on wizards for me I think.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:32
Joined
Oct 29, 2018
Messages
21,359
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom