Override On Load Event

Jallen182

New member
Local time
Today, 18:54
Joined
May 16, 2016
Messages
8
I'm Very New To Using VB in Access and I've come across an issue of not being able to override the on load event.
I'm in the process of creating a booking system where users must first create an account in a form (if no account exists already).
I have written a few lines of code into the OnLoad event to open a new blank form.
Once users have entered their personal information, the user then clicks on a "Next" button to enter credit card info in another form whilst also closing and saving the previous form.
On my second form i would like to have a "Back" button with an OnClick event that sends the user back to the previous form And most recent record instead of opening a new blank record again.

Is there any way to do this?

My code for the OnLoad event in the customer information form is as follows:

Code:
 Private Sub Form_Load()
    On Error Resume Next
    DoCmd.GoToRecord , , acNewRec
 End Sub

Currently the code i have written into the "Back" button on the credit card info form is as seen below;

Code:
 Private Sub btnBackToCustInfo_Click()
  On Error Resume Next
  DoCmd.OpenForm  "frmCreateAccountCust"
 End Sub

The only solution i have found to eradicate this issue currently is by simplifying the process, not closing any of the forms in the OnClick event when travelling from one form to the other until the booking process is complete.
 
Hi Jallen,

Generic process here would be to have a button on a form (Booking History?) to create a new booking. This opens the New Booking form. After the customer enters their account name.ID etc, carry out a Dcount() to verify the account exists and display the New Customers form if not (OR provide a combobox with the List Items Edit Form set to the New Customers form). After supplying new details, refresh the New Booking form before closing the New Customer form (and fill the customer account/ID box). Customer completes booking, click complete (or something) and you close the New Booking form, refreshing the Booking History form.
 
I would probably use the OpenArgs property.

Code:
Private Sub Form_Load()

    If Me.Openargs = "NotNew" Then 
         DoCmd.GoToRecord , , acLast
    Else
         DoCmd.GoToRecord , , acNewRec
    End IF

Exit Sub

Then on your back button

Code:
 Private Sub btnBackToCustInfo_Click()
  
  DoCmd.OpenForm  "frmCreateAccountCust" ,,,,,,"NotNew"
 
 End Sub
While you are developing I wouldn't use On Error Resume Next, it may hide errors you aren't aware are there, use an error handler with a msgbox showing you the error and/or comment them out whilst still building your application.
 
Not closing any forms is one way to do it. Are the forms bound to tables and is there a Primary Key that corresponds to the user?
 
Pretty slick use of the OpenArgs Minty. Going to have to remember that one...
 

Users who are viewing this thread

Back
Top Bottom