ADODB Recordset runtime error '3021'

  • Thread starter Thread starter Brian Hoffman
  • Start date Start date
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?
 
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] & "))"
 
Back
Top