VBA Type Mismatch

I am getting a TYPE mismatch with the following VBA code.

Sub CreateNHSNTbl()


Dim MyDb As DAO.Database
Dim qdef As DAO.QueryDef
Dim SQL As String
Dim strWhere As String
Dim startdt As Date
Dim enddt As Date

Set MyDb = CurrentDb()

startdt = DateSerial(2013, 7, 1)
enddt = DateSerial(2013, 7, 31)

strWhere = " WHERE(((dbo_AbstractData.PatientClass) <> 'IN')) " & _
strWhere = strWhere & "GROUP BY dbo_SchOrPatCases.SurgeonName, dbo_AbstractData.Name, dbo_AbstractData.BirthDateTime, dbo_AbstractData.UnitNumber, " & _
strWhere = strWhere & "dbo_SchAppointments.DateTime, dbo_SchAppointmentOrOperations.Description, dbo_SchOrPatCases.VisitID, dbo_AbstractData.AccountNumber " & _
strWhere = strWhere & "HAVING (((dbo_SchAppointments.DateTime) between " & [startdt] & " and " & [enddt] & " ));"

SQL = "SELECT dbo_SchOrPatCases.SurgeonName AS Surgeon, dbo_AbstractData.Name AS PTName, dbo_AbstractData.BirthDateTime AS DOB, " & _
SQL = SQL & "dbo_AbstractData.UnitNumber AS [MedRec#], dbo_SchAppointments.DateTime AS ProcDate, dbo_SchAppointmentOrOperations.Description AS ProcDescr " & _
SQL = SQL & " into tblNHSNProcedures " & _
SQL = SQL & " FROM (((((dbo_SchOrPatCases LEFT JOIN dbo_AbsOperationProcedures ON dbo_SchOrPatCases.VisitID = dbo_AbsOperationProcedures.VisitID) " & _
SQL = SQL & "LEFT JOIN dbo_AbstractData ON dbo_SchOrPatCases.VisitID = dbo_AbstractData.VisitID) LEFT JOIN dbo_AdmVisitOrders " & _
SQL = SQL & "ON dbo_SchOrPatCases.VisitID = dbo_AdmVisitOrders.VisitID) LEFT JOIN Sheet1 ON dbo_AbsOperationProcedures.ProcedureCode = Sheet1.ProcedureCode) " & _
SQL = SQL & "LEFT JOIN dbo_SchAppointments ON dbo_AbstractData.VisitID = dbo_SchAppointments.VisitID) LEFT JOIN dbo_SchAppointmentOrOperations " & _
SQL = SQL & "ON dbo_SchAppointments.AppointmentID = dbo_SchAppointmentOrOperations.AppointmentID " & _
SQL = SQL & strWhere


Set qdef = MyDb.CreateQueryDef("qry_NHSN_tbl", SQL)

DoCmd.OpenQuery "qry_NHSN_tbl"



End Sub


I do not see it.

Glen
GPSPOWAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Glen

The problem is the line continuation characters, so remove & _ throughout the code.

For example.
strWhere = " WHERE(((dbo_AbstractData.PatientClass) <> 'IN')) "
strWhere = strWhere & "GROUP BY dbo_SchOrPatCases.SurgeonName, dbo_AbstractData.Name, dbo_AbstractData.BirthDateTime, dbo_AbstractData.UnitNumber, "
strWhere = strWhere & "dbo_SchAppointments.DateTime, dbo_SchAppointmentOrOperations.Description, dbo_SchOrPatCases.VisitID, dbo_AbstractData.AccountNumber "
strWhere = strWhere & "HAVING (((dbo_SchAppointments.DateTime) between " & [startdt] & " and " & [enddt] & " ));"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GPSPOWAuthor Commented:
thanks that solved that problem.

My next is the data parameter:

startdt = DateSerial(2013, 7, 1)
enddt = DateSerial(2013, 7, 31)

strWhere = " WHERE(((dbo_AbstractData.PatientClass) <> 'IN')) "
strWhere = "and (dbo_SchAppointments.DateTime between " & [startdt] & " and " & [enddt] & " ) "
strWhere = strWhere & "GROUP BY dbo_SchOrPatCases.SurgeonName, dbo_AbstractData.Name, dbo_AbstractData.BirthDateTime, dbo_AbstractData.UnitNumber, "
strWhere = strWhere & "dbo_SchAppointments.DateTime, dbo_SchAppointmentOrOperations.Description, dbo_SchOrPatCases.VisitID, dbo_AbstractData.AccountNumber "
strWhere = ";"


The dbo_SchAppointments.DateTime  is not restricted to the variable startdt and enddt.

Glen
0
GPSPOWAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.