Cancel 'on load' event

Jagged

Registered User.
Local time
Today, 22:20
Joined
Aug 21, 2013
Messages
10
Hi


Anyone have the solution to this little problem?

I have a form (Pipeline) with an on load event that automatically directs the user to a new empty record.

Code:
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub

Now my problem is that I am trying to design a 'search form' that will allow the user to look up a specific record in the main form by pressing a command button. Creating the search form is easy enough. I cannot figure out how to override the on load event in the main form when pressing the command button.

Any ideas?

As it is right now, the button opens the form and then go directly to a new record.
 
Hello Jagged, Welcome to AWF.. :)

Do not use the OnLoad event.. Instead direct the button to open the form in the way you want it to.. If through the Search Form's button and you want to go to a specific record use the WHERE Condition..
Code:
DoCmd.OpenForm [B]yourFormName[/B], WhereCondition:="someControlName = 'someValue'"
If you want it to go to a New Record.. Use it like..
Code:
DoCmd.OpenForm [B]yourFormName[/B], DataMode:=acFormAdd
 
Thank you for the reply, however, it doesn't really solve my problem. Or maybe I dont understand it? :confused:

The way the database is setup, you are taken to an initial form, a navigation form basically with different options (command buttons). One of the takes you to the main case key-in form. That form has an on load event that directs you to a new record.

Another button takes you to a search form, that allows the user, through a series of combo boxes to select a specific case. After selecting inputs in the various boxes, you can hit a button which should take you to the main form again and display the right case. This is where a conflict with the on load event surfaces, it directs the user a blank record instead.
 
I think this is the case..
Or maybe I dont understand it?
Let me try to explain again..
The way the database is setup, you are taken to an initial form, a navigation form basically with different options (command buttons). One of the <button> takes you to the main case key-in form.
Code this button as I have shown earlier..
Code:
Private Sub[COLOR=Red][B] addNewRecord[/B][/COLOR]_Click()
    DoCmd.OpenForm yourFormName, DataMode:=acFormAdd
End Sub
Another button takes you to a search form, that allows the user, through a series of combo boxes to select a specific case. After selecting inputs in the various boxes, you can hit a <button>
Code this button to open the Form with the particular record, using the where condition..
Code:
Private Sub [COLOR=Blue][B]openExistingRecordBtn[/B][/COLOR]_Click()
    DoCmd.OpenForm yourFormName, WhereCondition:="someControlName = 'someValue'"
End Sub
Make sure you remove the On Load event from the Form.. For more clarity on how to use the where condition, read the Link I provided.. http://baldyweb.com/wherecondition.htm

Please let me know if I have misread your requirement and got everything wrong here..
 
Your right, I didn't read your reply closely enough. Works like a charm, thanks a bunch. Now back to lurking on this forum :)
 

Users who are viewing this thread

Back
Top Bottom