A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Open Form in Add Mode



 
 
Thread Tools Display Modes
  #1  
Old October 15th, 2009, 05:13 PM posted to microsoft.public.access.forms
Boreal2009
external usenet poster
 
Posts: 1
Default Open Form in Add Mode

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've been searching most of the day to try and figure this one out. Can
anyone provide me with detailed directions 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

  #2  
Old October 16th, 2009, 01:52 AM posted to microsoft.public.access.forms
Daniel Pineault
external usenet poster
 
Posts: 658
Default Open Form in Add Mode

If you indent your code the problem might become easier to spot.

Private Sub Form_Load()
If MsgBox("Is this a Re-Capture?", vbYesNo + vbInformation, _
"InformationNeeded ") = 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

According to your code if the user clicks YES then
DoCmd.RunMacro "Search Message MACRO"
DoCmd.RunCommand acCmdFind
and if the User clicks NO then
DoCmd.OpenForm "FORM - Male Capture Information", acNormal, _
, , acFormAdd, acWindowNormal, OpenArgs

You are actively opening the form in the NO case! You need to review your
if clause.

You might want to try something more like:

Private Sub Form_Load()
On Error GoTo Error_Handler

If MsgBox("Is this a Re-Capture?", vbYesNo + vbInformation, _
"InformationNeeded ") = vbYes Then
'If we are here it is because the user selected Yes
DoCmd.RunMacro "Search Message MACRO"
DoCmd.RunCommand acCmdFind
'Open the form in Edit Mode
DoCmd.OpenForm "FORM - Male Capture Information", acNormal, _
, , acFormEdit, acWindowNormal, OpenArgs
Else
'If we are here it is because the user selected No
'Open the form in Add Mode
DoCmd.OpenForm "FORM - Male Capture Information", acNormal, _
, , acFormAdd, acWindowNormal, OpenArgs
End If

Exit Sub

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: Form_Load" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Sub
End Sub

PS: Add Error handling code!
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Boreal2009" wrote:

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've been searching most of the day to try and figure this one out. Can
anyone provide me with detailed directions 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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:05 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.