Open a Form in Add Mode using Code

Boreal2009

Registered User.
Local time
Today, 13:49
Joined
Oct 5, 2009
Messages
10
Hi Everyone,
I am VERY new to VBA so please bear with me! I am using Access 2003 and I have a form that when it is loaded it prompts the user to answer a yes or no question. When yes is selected I want the form to open in Edit mode and when no is selected I want the form to open in Add mode.

Below is the code that is attached to the On Load Event. It works perfectly when yes is selected and opens the form in Edit mode. However, when no is selected, the form still opens in Edit mode. I have tried the same code in the On Open Event with the same results. It should also be noted that the form contains a subform.

I searched around for the better part of a day to try and figure this out which is how I developed the code below. Can anyone provide me with detailed instructions on how to solve this problem?

Thanks in advance!

Private Sub Form_Load()
If MsgBox("Is this a Re-Capture?", vbYesNo + vbInformation, "Information Needed") = vbYes Then
DoCmd.RunMacro "Search Message MACRO"
DoCmd.RunCommand acCmdFind
Else
DoCmd.OpenForm "FORM - Male Capture Information", acNormal, , , acFormAdd, acWindowNormal, OpenArgs
End If
End Sub
 
It appears taht thsi code may be in the form that you are trying to open. If this is true, then the form is alrady opened and you can not switch modes this way.

Normally the code you have would run somplace else, not in the form you want to open in Add mode.


I can think of a few possible solutions.

1) move the code to a command button.

In the On click event use:

Code:
If MsgBox("Is this a Re-Capture?", vbYesNo + vbInformation, "Information Needed") = vbYes Then

DoCmd.OpenForm "FORM - Male Capture Information", acNormal, , , , acWindowNormal, OpenArgs


DoCmd.RunMacro "Search Message MACRO"
DoCmd.RunCommand acCmdFind
Else
DoCmd.OpenForm "FORM - Male Capture Information", acNormal, , , acFormAdd, acWindowNormal, OpenArgs
End If

2) set the Data Entry property to true

Code:
Private Sub Form_Load()
If MsgBox("Is this a Re-Capture?", vbYesNo + vbInformation, "Information Needed") = vbYes Then
DoCmd.RunMacro "Search Message MACRO"
DoCmd.RunCommand acCmdFind
Else

   Me.DataEntry = True
   
End If
End Sub


3) just go to a new record


Code:
Private Sub Form_Load()
If MsgBox("Is this a Re-Capture?", vbYesNo + vbInformation, "Information Needed") = vbYes Then
DoCmd.RunMacro "Search Message MACRO"
DoCmd.RunCommand acCmdFind
Else

      DoCmd.GoToRecord , , acNewRec


End If
End Sub


.
 
Thanks Coach!

It's amazing how many ways one can skin a cat! Just before you responded I also found that the following code works as well:

...
Else
DoCmd.RunCommand acCmdRecordsGoToNew
End If

Thanks so much for your prompt reply - I put the same question out on a couple of forums yesterday and you are the only one who responded! Thanks again!:D
 
Glad you found a solution.

Thank you for posting your solution so others may benefit! :)
 

Users who are viewing this thread

Back
Top Bottom