Dear Friends
Can somebody varify the following code for me? It works in MS Access 2003, but not in 2010.
It ask me to debug at line
Set qryDef = CurrentDb.QueryDefs(strQueryName)
Thanks
Can somebody varify the following code for me? It works in MS Access 2003, but not in 2010.
It ask me to debug at line
Set qryDef = CurrentDb.QueryDefs(strQueryName)
Thanks
Code:
Option Compare Database
Private Sub Command2_Click()
Dim strCrit As String
Dim strCritNO As String 'Criteria for new old
Dim QueryName As String
Dim QueryName2 As String
Dim qryDef As DAO.QueryDef
Dim qryDef2 As DAO.QueryDef
Dim strSelect As String
Dim strSelect2 As String
strCrit = Me.cobCrit
strCritNO = Me.FirstDate
QueryName = "000MainService"
QueryName2 = "111OtherOR"
strNewT = newTable
strQueryName = QueryName
strQueryName2 = QueryName2
strSelect = "SELECT " & strCrit & " AS Period,"
strSelect = strSelect & strCritNO & " AS 1stDate,"
strSelect = strSelect & "[0000MainService].Code, [0000MainService].CaseMx, [0000MainService].Sex, [0000MainService].Age, [0000MainService].Risk1, [0000MainService].Risk2, [0000MainService].ProjSite, [0000MainService].Project, [0000MainService].Staff, [0000MainService].DorO, [0000MainService].Diagnosis, [0000MainService].DrugSex, [0000MainService].NDist, [0000MainService].SDist, [0000MainService].NSReturn, [0000MainService].DWater, [0000MainService].Condom, [0000MainService].DCSL, [0000MainService].FUCSL, [0000MainService].PreCSL, [0000MainService].Testing, [0000MainService].PostCSL, [0000MainService].FCSL, [0000MainService].PSC, [0000MainService].YCSL, [0000MainService].GCSL, [0000MainService].Referral, [0000MainService].To, [0000MainService].Fr, [0000MainService].For, [0000MainService].Meal, [0000MainService].HE, [0000MainService].Remark, [0000MainService].BHCID,[0000MainService].Dx1 from 0000MainService "
strSelect2 = "SELECT " & strCrit & " AS Period,"
strSelect2 = strSelect2 & "OtherOR.ORID, OtherOR.ProjSite, OtherOR.Project, OtherOR.ClientType, OtherOR.Male, OtherOR.Female, OtherOR.Condom, OtherOR.HE, OtherOR.Meal, OtherOR.Referral, OtherOR.To, OtherOR.For, OtherOR.Staff, OtherOR.Remark FROM OtherOR;"
Set qryDef = CurrentDb.QueryDefs(strQueryName)
Set qryDef2 = CurrentDb.QueryDefs(strQueryName2)
qryDef.SQL = strSelect
qryDef2.SQL = strSelect2
qryDef.Close
qryDef2.Close
'DoCmd.OpenQuery QueryName, acNormal, acEdit
'DoCmd.OpenQuery QueryName2, acNormal, acEdit
End Sub