Data Type Mismatch

Baldlegal

New member
Local time
Yesterday, 23:50
Joined
Apr 23, 2011
Messages
5
I keep getting a dta type mismatch error on a simple (I thought) onopen event. I'm trying to produce the records for a combo box from which the user can select the year for later processing. The choices should be this year and next year. The table Years has only one field, YearID, and it is a text field. I (try to) convert the available years to a string and include those values in a SQL SELECT statement but get the Data Type Mismatch error. Here's the code:

On Error GoTo Error_Handler

Dim strThisYear As String
Dim strNextYear As String

strThisYear = DatePart("yyyy", Now())
strThisYear = CStr(strThisYear)
strNextYear = Val(strThisYear) + 1
strNextYear = CStr(strNextYear)

Dim db As DAO.Database
Set db = CurrentDb()
Dim recset51 As Recordset
Set recset51 = CurrentDb.OpenRecordset("SELECT YEARS.YearID from Years where (((Years.YearID) = " & strThisYear & " or (Years.YearID) = " & strNextYear & "));")

Me!cboDuesYear.RowSource = recset51

Exit_Procedure:
On Error Resume Next
DoCmd.SetWarnings True
Exit Sub

Error_Handler:
DisplayUnexpectedError Err.Number, Err.Description
Resume Exit_Procedure
Resume

End Sub
 
Since it is a text field to have to enclose them within single quotes try this..
Code:
Set recset51 = CurrentDb.OpenRecordset("SELECT YEARS.YearID from Years where (((Years.YearID) = '" & strThisYear & "' or (Years.YearID) = '" & strNextYear & "'));")
 

Users who are viewing this thread

Back
Top Bottom