Why won't this code work

sir_aingeal

Registered User.
Local time
Today, 09:13
Joined
Nov 5, 2002
Messages
21
I have a main form with an option group with 6 choices, I want the user to choose one of the options which will then open a new form. The code I have on the OnClick for the group does not give me any error messages when a button is chosen but it also does not do anything. Any suggestions would be gratefully received.

Thanks
Iain

Code Follows.

Private Sub Division_Click()
Dim strSQL As String
Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim qry As String
Dim Whichdiv As Integer
Set rst = New ADODB.Recordset
'rst.Open , cnn, adOpenDynamic, adLockPessimistic
'Set strSQL = Division_Click()



Select Case Whichdiv
Case 1
DoCmd.OpenForm "frm_do_main", acNormal, , , , acWindowNormal
qry = "SELECT * FROM tbl_file_plans_divs WHERE (([tbl_file_plans_divs]![Division]=1));"
Case 2
DoCmd.OpenForm "frm_dod_main", acNormal, , , , acWindowNormal
qry = "SELECT * FROM tbl_file_plans_divs WHERE (([tbl_file_plans_divs]![Division]=2));"
Case 3
DoCmd.OpenForm "frm_scsd_main", acNormal, , , , acWindowNormal
qry = "SELECT * FROM tbl_file_plans_divs WHERE (([tbl_file_plans_divs]![Division]=3));"
Case 4
DoCmd.OpenForm "frm_csd_main", acNormal, , , , acWindowNormal
qry = "SELECT * FROM tbl_file_plans_divs WHERE (([tbl_file_plans_divs]![Division]=4));"
Case 5
DoCmd.OpenForm "frm_susd_main", acNormal, , , , acWindowNormal
qry = "SELECT * FROM tbl_file_plans_divs WHERE (([tbl_file_plans_divs]![Division]=5));"
Case 6
DoCmd.OpenForm "frm_rsad_main", acNormal, , , , acWindowNormal
qry = "SELECT * FROM tbl_file_plans_divs WHERE (([tbl_file_plans_divs]![Division]=6));"



End Select

End Sub
 
I don't see where you are setting WhichDiv to the value of your option group, so it should always be zero. Put a CASE ELSE and display the value of WhichDiv to verify.
 
Well, you've done this:
Dim Whichdiv As Integer
which initializes a variable called "Whichdiv" and then later on you've got:
Select Case Whichdiv
but no where have you got a statement assigning a value to "Whichdiv".

Sounds like you want to reference the value of the option group on your form, but you've got no code doing it.

If you've got an option group called "optDiv", then the code would make sense if it said:
Select Case optDiv etc...
 
So what changes would you suggest to make this work. Still trying to learn this code thing.

Iain.
 
I am guessing your option group name is Division?
Try this:
Select Case Me.Division

Do not know if you did not include all the code, but I see yu are assign a string value (a select) to qry, but you are not using it anywhere.
 
After SelectCase should be the name of the option group. If it is WhichDiv, no need for 'Dim WhichDiv as Integer'.

SelectCase Me!YourGroupName

Case1...

Case2...

End Select
 
That got it thanks.

Will be using the qry later hopefully, put it in there as i was thinking about it at the time.
 

Users who are viewing this thread

Back
Top Bottom