Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Combo Boxes - MS ACCESS 97

Status
Not open for further replies.

salisha

IS-IT--Management
Feb 24, 2003
28
US
I have two combo boxes. Depending on the Value I chose in Combo1, I need it to populate Combo2. This is how my code looks, but i keep getting a "Data Type Mismatch in Criteria Expression" when I click on combo2. What am i doing wrong????

Private Sub cboIssuance_AfterUpdate()
Dim dbs As DAO.database, rst As DAO.Recordset, stSQL As String, stSQL2 As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblLUSection")
stSQL = "Select Section_Code, Section from tblLUSection where Section_Code >= 50"
stSQL2 = &quot;Select Section_Code, Section from tblLUSection where Section_Code < 50&quot;

If Me.combo1 = &quot;S&quot; Then
Me.combo2.RowSourceType = &quot;Table/Query&quot;
Me.combo2.RowSource = stSQL
Else
Me.combo2.RowSourceType = &quot;Table/Query&quot;
Me.combo2.RowSource = stSQL2
End If

End Sub
 
HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Salisha,
The 50 in your query is evaluated as an integer while you probably have Section_Code as a string, therefore the message Type Mismatch.

Try with this code that I tesated successfully on my form.


Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Dim stSQL As String
Dim stSQL2 As String
Set dbs = CurrentDb

stSQL = &quot;Select Field from Table where Field >=&quot; & &quot;&quot;&quot;&quot; & &quot;50&quot; & &quot;&quot;&quot;&quot;
stSQL2 = &quot;Select Field from Table where Field <&quot; & &quot;&quot;&quot;&quot; & &quot;50&quot; & &quot;&quot;&quot;&quot;


With Me
!Combo1.RowSourceType = &quot;Table/Query&quot;

If !Combo1.Column(2) = &quot;S&quot; Then
!Combo2.RowSource = stSQL
Else
!Combo2.RowSource = stSQL2
End If

.Refresh
!Combo2.Value = &quot; &quot;
.Repaint

End With

Good Luck
 
thank you elisabeth. It worked. Thank You So mUch!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top