I have tried to get this code to work in a string SQL atatement with no luck. I am trying to concatenate two variables together within the SQL statement. Any help would be greatly appreciated.
Tom
Tom
Code:
Private Sub cmdXL_Click()
Dim sUCI As String
Dim sMon As String
Dim sCY As String
Dim sFileLoc As String
Dim sFile As String
Dim sSheet As String
Dim sFileType As String
Dim iRw As Integer
Dim sSQL As String
Dim rst As DAO.Recordset
Dim I As Integer
'MSP_Assists
sUCI = "MSP"
Call CurMonYrL(sUCI, sMon, sCY)
sFileLoc = "\\salmfilesvr1\public\Client Services\AutoRpts\_RptSets\OTHER\MSP\Tools\"
sFile = "MSP_Assists"
sSheet = "Assists_All"
sFileType = ".xlt"
Call xlOpen(sFileLoc, sUCI, sFile, sSheet, sFileType)
Range("A2").Value = sMon & " " & sCY
iRw = 5
'Data Assists
'Original code
'SELECT DICT_Dpt.rptdpt AS Department, z_ProcessPds.monstr AS BillMonth, DICT_Prov.rptprov AS Provider, [insdesc] & " (" & [insmne] & ")" AS Insurance, Sum(DATA_AssistData.Proc) AS Assists, Sum(DATA_AssistData.ChgAmt) AS Chgs, Sum(DATA_AssistData.WorkRVU) AS RVU
'FROM (((DATA_AssistData INNER JOIN z_ProcessPds ON DATA_AssistData.rptpd = z_ProcessPds.rptpd) INNER JOIN DICT_Dpt ON DATA_AssistData.Dpt = DICT_Dpt.dptid) INNER JOIN DICT_Prov ON DATA_AssistData.Prov = DICT_Prov.provid) INNER JOIN DICT_Ins ON DATA_AssistData.PrimInsMne = DICT_Ins.insmne
'WHERE (((z_ProcessPds.rptpddiff) = 1))
'GROUP BY DICT_Dpt.rptdpt, z_ProcessPds.monstr, DICT_Prov.rptprov, [insdesc] & " (" & [insmne] & ")"
'ORDER BY DICT_Dpt.rptdpt, DICT_Prov.rptprov, [insdesc] & " (" & [insmne] & ")";
sSQL = "SELECT DICT_Dpt.rptdpt AS Department, z_ProcessPds.mons AS BillMonth, DICT_Prov.rptprov AS Provider, [DICT_Ins.insdesc] & [DICT_Ins.insmne] AS Insurance, " & _
"Sum(DATA_AssistData.Proc) AS Assists, Sum(DATA_AssistData.ChgAmt) AS Chgs, Sum(DATA_AssistData.WorkRVU) AS RVU " & _
"FROM DATA_AssistData " & _
"INNER JOIN z_ProcessPds ON DATA_AssistData.rptpd = z_ProcessPds.rptpd " & _
"INNER JOIN DICT_Dpt ON DATA_AssistData.Dpt = DICT_Dpt.dptid " & _
"INNER JOIN DICT_Prov ON DATA_AssistData.Prov = DICT_Prov.provid " & _
"INNER JOIN DICT_Ins ON DATA_AssistData.PrimInsMne = DICT_Ins.insmne " & _
"WHERE z_ProcessPds.rptpddiff = 1) " & _
"GROUP BY DICT_Dpt.rptdpt, z_ProcessPds.mons, DICT_Prov.rptprov, [DICT_Ins.insdesc] & [DICT_Ins.insmne] AS Insurance & _
"ORDER BY DICT_Dpt.rptdpt, DICT_Prov.rptprov," & ""'" & [DICT_Ins.insdesc] & ""'" & [DICT_Ins.insmne] AS Insurance & ";""""
Debug.Print sSQL
Set rst = CurrentDb.OpenRecordset(sSQL, dbOpenSnapshot)
If Not rst.EOF Then
With rst
.MoveLast
.MoveFirst
End With
End If
For I = 1 To rst.RecordCount
With goXl.ActiveSheet
.Cells(iRw, 1).Value = (rst![ProvName])
.Cells(iRw + 1, 2).Value = (rst![Proc])
.Cells(iRw + 1, 3).Value = (rst![ChgAmt])
.Cells(iRw + 1, 4).Value = (rst![WorkRVU])
End With
iRw = iRw + 1
rst.MoveNext
Next I
MsgBox "WHOO! Source files are created.", , "Completed."
End Sub