473,473 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Opening Control Tab based on Option Group Selection

3 New Member
Hello.
In Access 2013, I have a control on one form that has 2 tabs. On another form, I have an option group with 2 options. I am trying to write it in VBA so that I select an option, click a button and based on the selection, the other form opens to the designated tab on the control.

Here is what I have on the Click event of the button:
(I build some tables upon opening the other form)

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdclose_Click()
  2. On Error GoTo cmdclose_Click_Err
  3.  
  4.     DoCmd.OpenQuery "appq_cct_date", acViewNormal
  5.     DoCmd.OpenQuery "appq_cust_date", acViewNormal
  6.     DoCmd.OpenQuery "appq_customer", acViewNormal
  7.     DoCmd.OpenQuery "appq_cct", acViewNormal
  8.  
  9.     If frmetype = "1" Then
  10.         DoCmd.OpenForm "frm_sec_menu", acNormal
  11.         TabCtlSEC.Pages(0).SetFocus
  12.     ElseIf frmetype = "2" Then
  13.         DoCmd.OpenForm "frm_sec_menu", acNormal
  14.         TabCtlSEC.Pages(1).SetFocus
  15.     End If
  16.  
  17.  
  18. cmdclose_Click_Exit:
  19.     Exit Sub
  20.  
  21. cmdclose_Click_Err:
  22.     MsgBox Error$
  23.     Resume cmdclose_Click_Exit
  24.  
  25. End Sub
  26.  
The form opens but not to the corresponding page and I am getting "Object required"

Thanks.
Jan 13 '16 #1
4 1175
NeoPa
32,556 Recognized Expert Moderator MVP
Three points here :
  1. I've copied your code and it works fine for me. I've assumed that the objects you've referenced are all named accurately. Possibly not in your case, as that's what I suspect is causing you the main problem.
  2. Generally, when developing code, it's easier to do it without any error handling enabled. This way you get to see (and report for us of course) which line the code fails on and the full error message. Context is all.
  3. When adding in the error handling remember that the code label names need be unique only within the procedure. Thus, it makes sense to have simpler labels like :
    Expand|Select|Wrap|Line Numbers
    1. Error_Handler:
    2. ExitPoint:
    It gives consistency to your code and makes it easier to read.
So, first put away the error handling until you have it working reliably, then check the spellings of all items.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdClose_Click()
  2. 'On Error GoTo ErrorHandler
  3.  
  4.     DoCmd.OpenQuery "appq_cct_date", acViewNormal
  5.     DoCmd.OpenQuery "appq_cust_date", acViewNormal
  6.     DoCmd.OpenQuery "appq_customer", acViewNormal
  7.     DoCmd.OpenQuery "appq_cct", acViewNormal
  8.  
  9.     Select Case frmEType
  10.     Case "1", "2"            'Are they really string values?
  11.         Call DoCmd.OpenForm("frm_sec_menu", acNormal)
  12.         Call TabCtlSEC.Pages(Val(frmEType)).SetFocus
  13.     End Select
  14.  
  15. ExitPoint:
  16.     Exit Sub
  17.  
  18. ErrorHandler:
  19.     Call MsgBox(Err.Description)
  20.     Resume ExitPoint
  21.  
  22. End Sub
Jan 14 '16 #2
minjacks
3 New Member
Thanks! Turning off the error handling was very helpful.

The code you provided did stop the 'Object required' problem, however, it wouldn't open the form.

This is what worked for me:
(The frmetype "1" and "2" are the option values)

Expand|Select|Wrap|Line Numbers
  1.  If frmetype = "1" Then
  2.         DoCmd.OpenForm "frm_sec_menu", acNormal
  3.         DoCmd.GoToControl ("...name of control page 0...")
  4.     ElseIf frmetype = "2" Then
  5.         DoCmd.OpenForm "frm_sec_menu", acNormal
  6.         DoCmd.GoToControl ("...name of control page 1...")
  7.  
  8.     End If
  9.  
Again, thank you for the reply. Even though I didn't use your proposed code, your response was very helpful for me. Have a great day!
Jan 14 '16 #3
NeoPa
32,556 Recognized Expert Moderator MVP
If you're happier doing it that way then go for it. As I say, I found even your original code worked ok in my tests. Obviously mine did too on my system. It's hard to say what might have happened in the copying.

At the end of the day though, you have a working solution and that's the most important thing really.
Jan 17 '16 #4
mbizup
80 New Member
A couple of comments - I can't recall the exact circumstances, but I have also had trouble with the SetFocus method on tab controls (I'm unable to reproduce that at the moment, of course :-)). Those issues led me to use other methods to control tab pages in code.

Tab controls have a zero based Value property, which determines the page that is open:
Expand|Select|Wrap|Line Numbers
  1. Me.myTabControl.Value = SomeInteger
  2. 'or simply:
  3. Me.myTabControl = SomeInteger
With an option group using the default settings (sequential numbers starting at 1), you can control tab pages like this. The "-1" handles the zero-based tabcontrol values (Page 1 is 0, Page 2 is 1, etc):

Expand|Select|Wrap|Line Numbers
  1. myTabControl = MyOptionGroup - 1
MinJacks:
I have a control on one form that has 2 tabs. On another form, I have an option group with 2 options.
If the option group is indeed on a separate form from the tab control, I would have thought you'd need the full form reference to the tab control in any code to get this working:

Expand|Select|Wrap|Line Numbers
  1. Forms!frm_sec_menu.TabCtlSEC = (frmetype.Value - 1)
(If it ain't broke, don't fix it of course... this topic just piqued my curiosity.)
Jan 18 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joscarfas | last post by:
Hello to all, As you can read the subject of this post, this is exactly what I'm trying to do. I need to disable some controls in my form base on secutiry level in MS Access; I've been...
1
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
2
by: Charles | last post by:
Ok, so I'm creating a form on the fly. I can create the option group, I can create the checkboxes, but I can't figure out how to bind them to the option group I'm creating them within. I was...
3
by: El | last post by:
I can get a total count for a whole option group field, but I need to be able to count each individual selection in an option group on a report. For example if I had a yes or no option...I would...
2
by: kickergirl | last post by:
I am creating a rather unwieldy database (MS Access 2000) in which the client wants to provide the users with an "Other" option for every option group. The client also wishes the user to explain...
2
by: mmath | last post by:
Hello! Here is the code I'm working with: Private Sub opbAddNew_Click() Dim rstRiskRating As ADODB.Recordset Set rstRiskRating = New ADODB.Recordset With rstRiskRating ...
1
by: EORTIZ | last post by:
I need to be able to delete a selection from an option group control in a form. In other words, if I selected value 1 from the option group control and I should have left blank this control.
0
tuxalot
by: tuxalot | last post by:
Hello all, I have a 2 column table that looks like such 1 apple 2 banana 3 orange 4 tomato 5 strawberry
1
by: Emily Walshaw | last post by:
I'm sorry, I know this has been asked a million times, but am completely new to access and need idiot proof help. I have a database and I am struggling to get a field to update based on a combobox...
2
by: matthais86 | last post by:
Hi. I work for a small consumer PC repair company as a workshop technician, but have recently been tossed into the deep end on coding an Access/VBA system for a client despite not having used VB...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.