Help with Event Procedure

tcarriero
NewLounger
Posts: 15
Joined: 10 Feb 2010, 20:13

Help with Event Procedure

Post by tcarriero »

I would like to create a button to show and hide the history on my form. It worked well when I added the first button but now I'm getting the following error message:

The expression On Open you entered as the event property setting produced the following error: Ambiguous name detected: Form_Open.

Can you please tell me what change I need to make? I need to add four other history buttons to the form and I don't know if I have things in the wrong place or named wrong...

Private Sub cmdDetail_Click()
Me![frmStatus1_HISTORY].Visible = Not Me![frmStatus1_HISTORY].Visible
If Me![frmStatus1_HISTORY].Visible Then
Me![cmdDetail].Caption = "Hide History"
Else
Me![cmdDetail].Caption = "Show History"
End If
End Sub

Private Sub Form_Open(Cancel As Integer)
Me![frmStatus1_HISTORY].Visible = False
Me![cmdDetail].Caption = "Show History"
End Sub

Private Sub cmdHistory_Click()
Me![frmStatus2_HISTORY].Visible = Not Me![frmStatus2_HISTORY].Visible
If Me![frmStatus2_HISTORY].Visible Then
Me![cmdHistory].Caption = "Hide History"
Else
Me![cmdHistory].Caption = "Show History"
End If
End Sub

Private Sub Form_Open(Cancel As Integer)
Me![frmStatus2_HISTORY].Visible = False
Me![cmdHistory].Caption = "Show History"
End Sub

User avatar
HansV
Administrator
Posts: 78386
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with Event Procedure

Post by HansV »

You have two procedures named Form_Open. That is not allowed - you can have only one procedure of a given name. You can, however, combine the code from the two procedures into one of them, and add more code if necessary:

Code: Select all

Private Sub Form_Open(Cancel As Integer)
  Me![frmStatus1_HISTORY].Visible = False
  Me![cmdDetail].Caption = "Show History"
  Me![frmStatus2_HISTORY].Visible = False
  Me![cmdHistory].Caption = "Show History"
End Sub
After doing this, you should remove the other instance of Form_Open.
Best wishes,
Hans

tcarriero
NewLounger
Posts: 15
Joined: 10 Feb 2010, 20:13

Re: Help with Event Procedure

Post by tcarriero »

That worked. THANK YOU HANS! and thank you for letting me know you moved to Eileen's Lounge. Your explanations have always been easy to understand and for that I am truely grateful. Please let me know if you ever publish an Access book.

User avatar
HansV
Administrator
Posts: 78386
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Help with Event Procedure

Post by HansV »

I'm glad you joined us - welcome here!

(It's not very likely I'll write an Access book...)
Best wishes,
Hans