data type mismatch in A2007, but not A2003

S

Song Su

I had A2003 and following code works fine. After I converted to A2007, it
gives me 'data type mismatch. I did not change anything. It pointed to Set
rst line. here is the code:

Private Sub Sect_BeforeUpdate(Cancel As Integer)
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Select * From qryData Where [sect] =
'" & Me.Sect _
& "' And [TimeIn] >= #" & [Forms]![MainMenu].[From] & _
"# And [TimeOut] <= #" & [Forms]![MainMenu].[To] + 1 & "#")
If rst.EOF Then
MsgBox Me.Sect & " is not valid section #, or" & vbCrLf _
& "no student signed in " & Me.Sect & " during the period
specified.", , conAppName
Cancel = True
Else
Me.Course = rst![Course]
End If
Set rst = Nothing

Exit_sect_BeforeUpdate:
Exit Sub
Err_sect_BeforeUpdate:
MsgBox Err.Description
Resume Exit_sect_BeforeUpdate

End Sub
 
T

Tom van Stiphout

Check your References. Perhaps you have one for ADO rather than DAO.

-Tom.
Microsoft Access MVP
 
D

Douglas J. Steele

Or perhaps Song Su has references to both ADO and DAO, and needs to
disambiguate the declaration as

Dim rst As DAO.Recordset

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Tom van Stiphout said:
Check your References. Perhaps you have one for ADO rather than DAO.

-Tom.
Microsoft Access MVP

I had A2003 and following code works fine. After I converted to A2007, it
gives me 'data type mismatch. I did not change anything. It pointed to Set
rst line. here is the code:

Private Sub Sect_BeforeUpdate(Cancel As Integer)
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Select * From qryData Where [sect]
=
'" & Me.Sect _
& "' And [TimeIn] >= #" & [Forms]![MainMenu].[From] & _
"# And [TimeOut] <= #" & [Forms]![MainMenu].[To] + 1 & "#")
If rst.EOF Then
MsgBox Me.Sect & " is not valid section #, or" & vbCrLf _
& "no student signed in " & Me.Sect & " during the period
specified.", , conAppName
Cancel = True
Else
Me.Course = rst![Course]
End If
Set rst = Nothing

Exit_sect_BeforeUpdate:
Exit Sub
Err_sect_BeforeUpdate:
MsgBox Err.Description
Resume Exit_sect_BeforeUpdate

End Sub
 

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