B
Basil
Hiya.
I have a form with 2 combo boxes. 1 is dependent on the other.
1. cbo_Division
2. cbo_Function
The intention is that when the Division is selected, the function combobox
will be populated with those functions within the selected division.
I got this to work no problems (without using code - just a smart row source
query in cbo_Function that references cbo_Division).
Then I realised that some divisions have no functions within them. For these
I wanted to disable cbo_Function when these divisions were selected. But I
can't get my code to work (chucks up the 'Too few parameters. Expected 1'
error). Can anyone help?
Code (I got rid of most dims (rst As recordset etc), but might put them back
- same error regardless):
Private Sub cbo_Division_Change()
Dim sqlstring As String
sqlstring = cbo_Function.RowSource
If CurrentDb.OpenRecordset(sqlstring).RecordCount = 0 Then
cbo_Function.Enabled = False
Else
cbo_Function.Enabled = True
End If
End Sub
SQL:
SELECT [tbl_Function].[Function_ID], [tbl_Function].[Function_Name] FROM
tbl_Function WHERE
((([tbl_Function].[Division_ID])=[Forms]![frm_Projects]![cbo_Division]));
Thanks,
Basil
I have a form with 2 combo boxes. 1 is dependent on the other.
1. cbo_Division
2. cbo_Function
The intention is that when the Division is selected, the function combobox
will be populated with those functions within the selected division.
I got this to work no problems (without using code - just a smart row source
query in cbo_Function that references cbo_Division).
Then I realised that some divisions have no functions within them. For these
I wanted to disable cbo_Function when these divisions were selected. But I
can't get my code to work (chucks up the 'Too few parameters. Expected 1'
error). Can anyone help?
Code (I got rid of most dims (rst As recordset etc), but might put them back
- same error regardless):
Private Sub cbo_Division_Change()
Dim sqlstring As String
sqlstring = cbo_Function.RowSource
If CurrentDb.OpenRecordset(sqlstring).RecordCount = 0 Then
cbo_Function.Enabled = False
Else
cbo_Function.Enabled = True
End If
End Sub
SQL:
SELECT [tbl_Function].[Function_ID], [tbl_Function].[Function_Name] FROM
tbl_Function WHERE
((([tbl_Function].[Division_ID])=[Forms]![frm_Projects]![cbo_Division]));
Thanks,
Basil