Cascading Combo Boxes with Option Button

hanarina

Registered User.
Local time
Today, 14:12
Joined
Oct 29, 2012
Messages
14
Guys~
I have this SQL code but I'm not sure what wrong with it. it seems to work but the problem is when i click my combo box, nothing is there(no data at all, I already set the data source).

Here is the code

Option Compare Database

Private Sub Form_Current()
On Error Resume Next
Dim strProg As String
If IsNull(cmbName.Value) Then
ProGrp.Value = Null
End If

strProg = DLookup("[programme]", "Table1", "[Name]='" & cmbName.Value & "'")
Select Case strProg
Case "Computer"
ProGrp.Value = 1
MsgBox "Your have been checked."
Case "Accounting"
ProGrp.Value = 2
Case "Interior"
ProGrp.Value = 3
End Select

cmbName.RowSource = "Select Table1.Name " & _
"FROM Table1 " & _
"WHERE Table1.programme = '" & strProg & "' " & _
"ORDER BY Table1.Name;"
End Sub


Private Sub ProGrp_AfterUpdate()
On Error Resume Next
Dim strProg As String
Select Case ProGrp.Value
Case 1
strProg = "Computer"
MsgBox "Your have been checked."
Case 2
strProg = "Accounting"
Case 3
strProg = "Interior"
End Select
cmbName.RowSource = "Select Table1.Name " & _
"FROM Table1 " & _
"WHERE Table1.programme = '" & strProg & "' " & _
"ORDER BY Table1.Name;"
End Sub


Thanks..
 

Attachments

  • Untitled1.jpg
    Untitled1.jpg
    27.6 KB · Views: 94
Well, considering NAME (An Access Reserved Word) is one of the worst things you can use for a field or object name, I'm not surprised. You really should change that. Name your field ProgramName or something, anything but NAME.

And, as far as this current situation is you need brackts because of using an Access Reserved Word:

"Select Table1.[Name] " & _
"FROM Table1 " & _
"WHERE Table1.programme = '" & strProg & "' " & _
"ORDER BY Table1.[Name];"
 
Well, considering NAME (An Access Reserved Word) is one of the worst things you can use for a field or object name, I'm not surprised. You really should change that. Name your field ProgramName or something, anything but NAME.

And, as far as this current situation is you need brackts because of using an Access Reserved Word:

"Select Table1.[Name] " & _
"FROM Table1 " & _
"WHERE Table1.programme = '" & strProg & "' " & _
"ORDER BY Table1.[Name];"

I changed the NAME to StudName but it still didnt work..
Here I attach my dBase..
 

Attachments

Your problem is very simple. Your combo box should have its

COLUMN COUNT property set to 1 not 2
COLUMN WIDTH property set to 1" not 0";1";1"
 
Your problem is very simple. Your combo box should have its

COLUMN COUNT property set to 1 not 2
COLUMN WIDTH property set to 1" not 0";1";1"

Btw how can I make my combo box to view all the name list when non of the option box is selected?
 

Users who are viewing this thread

Back
Top Bottom