Hide tab macro (1 Viewer)

nick5196

Registered User.
Local time
Today, 07:37
Joined
Feb 17, 2011
Messages
43
Hi, I'm (trying to) create an access database containing a form with multiple tabs. My objective is to make a button with a module that will hide (make not visible or disable) one of the tabs if a combobox has a specific value. Essentially, I want to hide the tab 'qA' if the combobox has a value of 'AA'. The problem appears to be referring to the correct tab within the form. I've been trying to do this for a couple of hours and have been through many error messages, so any help would be greatly appreciated.

I've attached a copy of the database to help prevent confusion.

Thanks allot, I really appreciate it,
Nick
 

Attachments

  • test 2.accdb
    328 KB · Views: 122

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:37
Joined
Aug 30, 2003
Messages
36,129
Don't have 2007 on this machine, but the code would look like:

Code:
  If Me.ComboName = "AA" Then
    Me.PageName.Visible = False
  Else
    Me.PageName.Visible = True
  End If

Where PageName is the name of the tab (name, not caption).
 

nick5196

Registered User.
Local time
Today, 07:37
Joined
Feb 17, 2011
Messages
43
I tried this but experienced an error message; "invalid use of the word "Me"". I have experienced this before, possibly it is to do with how I am defining the tab? I found these methods of referring to a single tab but am unsure which to use and how to implement them.

Thanks allot for trying
 

CBrighton

Surfing while working...
Local time
Today, 15:37
Joined
Nov 9, 2010
Messages
1,012
If it's just the me it doesn't like...

Code:
  If Forms!FormName!ComboName = "AA" Then
    Forms!FormName!PageName.Visible = False
  Else
    Forms!FormName!PageName.Visible = True
  End If

:edit:

If the tab control is in a subform and the combo box in the main form then slightly different code is needed:

Code:
  If Forms!FormName!ComboName = "AA" Then
    Forms!FormName!SubFormControlName.form!PageName.Visible = False
  Else
    Forms!FormName!SubFormControlName.form!PageName.Visible = True
  End If
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:37
Joined
Aug 30, 2003
Messages
36,129
Where exactly do you have the code?
 

nick5196

Registered User.
Local time
Today, 07:37
Joined
Feb 17, 2011
Messages
43
Just tried this method and received an error which read "this visual basic module contains a syntax error".
Heres a copy and paste of what I have written:
If Forms!add_details!course = "AA" Then
Forms!add_details!qa.Visible = False
Else
Forms!add_details!qa.Visible = True
End If
Not sure where the errors are.

Thanks allot for your help.
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
It needs to go in the combo's AFTER UPDATE event and this works (I just tested):
Code:
Private Sub course_AfterUpdate()
    If Me.course = "AA" Then
        Me.qAA.Visible = False
    Else
        Me.qAA.Visible = True
    End If
End Sub

If the code isn't firing for you need to do this.
 

nick5196

Registered User.
Local time
Today, 07:37
Joined
Feb 17, 2011
Messages
43
Pbaldy:
I am creating the code as a module and the creating a macro to run the code.
I am then assigning it to the "course" combo box.
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
Pbaldy:
I am creating the code as a module and the creating a macro to run the code.
I am then assigning it to the "course" combo box.
Too much - just put it in the combo's After Update event. No need for the other module and no need for the macro.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:37
Joined
Aug 30, 2003
Messages
36,129
In a standard module you would need the full form reference.
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
Here is the copy back with it working.
 

Attachments

  • test 2.accdb
    324 KB · Views: 151

Users who are viewing this thread

Top Bottom