ADODB Recordset runtime error '3021'

B

Brian Hoffman

If Len(cboType) > 0 Then

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim rst1 As New ADODB.Recordset
rst1.ActiveConnection = cnn1

Dim mySQL As String
mySQL = "SELECT [PKResType#] FROM tblResTypes"
mySQL = mySQL + " WHERE (([Resource]='Me.[cboRes]')"
mySQL = mySQL + " AND ([Type]='Me.[cboType]'))"

rst1.Open mySQL
rst1.MoveFirst

I am fairly new to programming, so I have taken alot of my work directly
from textbooks. Can anyone explain why BOF and EOF are true here?
 
D

Douglas J. Steele

Your references to cboRes and cboType must be outside of the quotes.

mySQL = mySQL & " WHERE (([Resource]='" & Me.[cboRes] & "')"
mySQL = mySQL & " AND ([Type]=" & Me.[cboType] & "))"

Look at the difference in what I put there: I've assumed that Resource is a
text field, while Type is a numeric field. Exagerated for clarity, that's

mySQL = mySQL & " WHERE (([Resource]=' " & Me.[cboRes] & " ' )"
mySQL = mySQL & " AND ([Type]=" & Me.[cboType] & "))"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top