I Am using access 2003. I am trying to pull information from a table without much luck I am getting a syntax error. I have been trying to track down where I have made the error without much luck. I have 5 fields from a table that I am trying to export to an excel sheet. Any help would be appreciated.
The name of the tables are: fields
DAT_Pats PatName AcctNu aid
DAT_ReportData aid uci rptpd doschg ChgAmt pmts
I need to join the two tables using the aid field
I started with copying the code directly from a query that works
The name of the tables are: fields
DAT_Pats PatName AcctNu aid
DAT_ReportData aid uci rptpd doschg ChgAmt pmts
I need to join the two tables using the aid field
I started with copying the code directly from a query that works
Code:
'SQL from query
SELECT DAT_ReportData.uci, DAT_ReportData.rptpd, DAT_Pats.PatName, DAT_Pats.AcctNu, DAT_ReportData.doschg, DAT_ReportData.ChgAmt, DAT_ReportData.pmts
FROM DAT_ReportData INNER JOIN DAT_Pats ON DAT_ReportData.aid = DAT_Pats.aid
WHERE (((DAT_ReportData.rptpd)=[Enter Period]))
ORDER BY DAT_Pats.PatName, DAT_ReportData.doschg;
'code in access
'alias DatRpt
strSQL = "SELECT DAT_Pats.PatName, DAT_Pats.AcctNu," & _
"DatRpt.doschg, DatRpt.ChgAmt, DatRpt.pmts" & _
"FROM DAT_ReportData DatRpt" & _
"INNER JOIN DAT_Pats ON DatRpt.aid = DAT_Pats.aid" & _
"WHERE (((DatRpt.rptpd) = strCurrentMonth))" & _
"ORDER BY DAT_Pats.PatName, ;"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot) Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If (rst.RecordCount > 0) Then
With rst
.MoveLast
.MoveFirst
End With
'Set up the first data row on excel template AnestheticSolutions_2.xlt
iRwCnt = 7 ' Row starts at 7
iBegRow = 7 ' First iBegRow
'iEndRow = 5 ' First iEndRow
strCurYr = rst![Yr]
strGrpYr = rst![Yr]
'Sets 1st year
End If
' 'Counter to loop through all records
For Z = 1 To rst.RecordCount
With goXL.ActiveSheet
.Cells(iRwCnt, 1) = rst![1]
.Cells(iRwCnt, 2) = rst![2]
.Cells(iRwCnt, 3) = rst![3]
.Cells(iRwCnt, 4) = rst![4]
.Cells(iRwCnt, 5) = rst![5]
End With
rst.MoveNext
iRwCnt = iRwCnt + 1