eyesonthebal
12-24-2015, 10:30 AM
Hi, Everyone:
I'm currently trying to write VBA code for a macro in Excel that makes use of some SQL, but for some reason, I'm getting the message, "ORA-00936: missing expression", when I execute the macro. Please see below for the portion of the code involving my SQL code. In particular, the very last line of code generates the error. IDField, IDFieldAlias, MonthIndex_p, YearIndex_p, Group_p, Charge, NextMonthIndex and NextYearIndex are all defined variables (either strings or integers) in my code. This SQL code works in Access, but not in VBA, which I've noticed happens somewhat often in practice. Any help with identifying the problem with the syntax in the below code would be greatly appreciated. If there are any questions, please feel free to ask.
___________________________________________________________________________ ___________________________________________________________________________ ___________________________________
SQLCode = "SELECT ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR, ELIG.ENROLLMENT_EPISODE_DEF_V.DIV_NBR, RIGHT([ELIG.PERSON_1.SSN],4) AS SSN, ELIG.ENROLL_IN_FAMILY." & IDField & " AS " & IDFieldAlias & ", " & _
"ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR AS [ALTUS INTERNAL ID], ELIG.PERSON.FNAME, ELIG.PERSON.LNAME, ELIG.ENROLL_IN_FAMILY.REL_CODE, '" & Charge & "' AS CHARGE, " & _
"ELIG.ENROLLMENT_EPISODE_DEF_V.EFF_DATE, ELIG.ENROLLMENT_EPISODE_DEF_V.LIM_DATE FROM ((ELIG.ENROLLMENT_EPISODE_DEF_V INNER JOIN ELIG.ENROLL_IN_FAMILY ON " & _
"(ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR = ELIG.ENROLL_IN_FAMILY.ENROLL_PERS_NBR) AND (ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR = ELIG.ENROLL_IN_FAMILY.GRP_NBR) AND " & _
"(ELIG.ENROLLMENT_EPISODE_DEF_V.DIV_NBR = ELIG.ENROLL_IN_FAMILY.DIV_NBR) AND (ELIG.ENROLLMENT_EPISODE_DEF_V.SUB_PERS_NBR = ELIG.ENROLL_IN_FAMILY.SUB_PERS_NBR)) INNER JOIN " & _
"ELIG.PERSON ON ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR = ELIG.PERSON.PERS_NBR) INNER JOIN ELIG.PERSON AS ELIG.PERSON_1 ON ELIG.ENROLLMENT_EPISODE_DEF_V.SUB_PERS_NBR = " & _
"ELIG.PERSON_1.PERS_NBR WHERE (((DateDiff('yyyy',[ELIG.PERSON.DOB],'" & MonthIndex_p & "/1/" & YearIndex_p & "') + Int(Format('" & MonthIndex_p & "/1/" & YearIndex_p & "','mmdd')<" & _
"Format([ELIG.PERSON.DOB],'mmdd'))) < 19)) GROUP BY ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR, ELIG.ENROLLMENT_EPISODE_DEF_V.DIV_NBR, RIGHT([ELIG.PERSON_1.SSN],4), " & _
"ELIG.ENROLL_IN_FAMILY." & IDField & ", ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR, ELIG.PERSON.FNAME, ELIG.PERSON.LNAME, ELIG.ENROLL_IN_FAMILY.REL_CODE, '" & Charge & "', " & _
"ELIG.ENROLLMENT_EPISODE_DEF_V.EFF_DATE, ELIG.ENROLLMENT_EPISODE_DEF_V.LIM_DATE HAVING (((ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR) In (" & Group_p & ")) AND " & _
"((ELIG.ENROLLMENT_EPISODE_DEF_V.EFF_DATE)< TO_DATE('" & NextMonthIndex & "/1/" & NextYearIndex & "','MM-DD-YYYY')) AND ((ELIG.ENROLLMENT_EPISODE_DEF_V.LIM_DATE)>" & _
"TO_DATE('" & MonthIndex_p & "/1/" & YearIndex_p & "','MM-DD-YYYY')))"
Set Records = New ADODB.Recordset
Records.Open SQLCode, Conn_p, adOpenStatic, adLockReadOnly
___________________________________________________________________________ ___________________________________________________________________________ ___________________________________
Thank you all, and happy holidays!
Best,
David
I'm currently trying to write VBA code for a macro in Excel that makes use of some SQL, but for some reason, I'm getting the message, "ORA-00936: missing expression", when I execute the macro. Please see below for the portion of the code involving my SQL code. In particular, the very last line of code generates the error. IDField, IDFieldAlias, MonthIndex_p, YearIndex_p, Group_p, Charge, NextMonthIndex and NextYearIndex are all defined variables (either strings or integers) in my code. This SQL code works in Access, but not in VBA, which I've noticed happens somewhat often in practice. Any help with identifying the problem with the syntax in the below code would be greatly appreciated. If there are any questions, please feel free to ask.
___________________________________________________________________________ ___________________________________________________________________________ ___________________________________
SQLCode = "SELECT ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR, ELIG.ENROLLMENT_EPISODE_DEF_V.DIV_NBR, RIGHT([ELIG.PERSON_1.SSN],4) AS SSN, ELIG.ENROLL_IN_FAMILY." & IDField & " AS " & IDFieldAlias & ", " & _
"ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR AS [ALTUS INTERNAL ID], ELIG.PERSON.FNAME, ELIG.PERSON.LNAME, ELIG.ENROLL_IN_FAMILY.REL_CODE, '" & Charge & "' AS CHARGE, " & _
"ELIG.ENROLLMENT_EPISODE_DEF_V.EFF_DATE, ELIG.ENROLLMENT_EPISODE_DEF_V.LIM_DATE FROM ((ELIG.ENROLLMENT_EPISODE_DEF_V INNER JOIN ELIG.ENROLL_IN_FAMILY ON " & _
"(ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR = ELIG.ENROLL_IN_FAMILY.ENROLL_PERS_NBR) AND (ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR = ELIG.ENROLL_IN_FAMILY.GRP_NBR) AND " & _
"(ELIG.ENROLLMENT_EPISODE_DEF_V.DIV_NBR = ELIG.ENROLL_IN_FAMILY.DIV_NBR) AND (ELIG.ENROLLMENT_EPISODE_DEF_V.SUB_PERS_NBR = ELIG.ENROLL_IN_FAMILY.SUB_PERS_NBR)) INNER JOIN " & _
"ELIG.PERSON ON ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR = ELIG.PERSON.PERS_NBR) INNER JOIN ELIG.PERSON AS ELIG.PERSON_1 ON ELIG.ENROLLMENT_EPISODE_DEF_V.SUB_PERS_NBR = " & _
"ELIG.PERSON_1.PERS_NBR WHERE (((DateDiff('yyyy',[ELIG.PERSON.DOB],'" & MonthIndex_p & "/1/" & YearIndex_p & "') + Int(Format('" & MonthIndex_p & "/1/" & YearIndex_p & "','mmdd')<" & _
"Format([ELIG.PERSON.DOB],'mmdd'))) < 19)) GROUP BY ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR, ELIG.ENROLLMENT_EPISODE_DEF_V.DIV_NBR, RIGHT([ELIG.PERSON_1.SSN],4), " & _
"ELIG.ENROLL_IN_FAMILY." & IDField & ", ELIG.ENROLLMENT_EPISODE_DEF_V.DEP_PERS_NBR, ELIG.PERSON.FNAME, ELIG.PERSON.LNAME, ELIG.ENROLL_IN_FAMILY.REL_CODE, '" & Charge & "', " & _
"ELIG.ENROLLMENT_EPISODE_DEF_V.EFF_DATE, ELIG.ENROLLMENT_EPISODE_DEF_V.LIM_DATE HAVING (((ELIG.ENROLLMENT_EPISODE_DEF_V.GRP_NBR) In (" & Group_p & ")) AND " & _
"((ELIG.ENROLLMENT_EPISODE_DEF_V.EFF_DATE)< TO_DATE('" & NextMonthIndex & "/1/" & NextYearIndex & "','MM-DD-YYYY')) AND ((ELIG.ENROLLMENT_EPISODE_DEF_V.LIM_DATE)>" & _
"TO_DATE('" & MonthIndex_p & "/1/" & YearIndex_p & "','MM-DD-YYYY')))"
Set Records = New ADODB.Recordset
Records.Open SQLCode, Conn_p, adOpenStatic, adLockReadOnly
___________________________________________________________________________ ___________________________________________________________________________ ___________________________________
Thank you all, and happy holidays!
Best,
David