Hello all,
I am counting contacts through using the field "SCHDL_REFNO" as my count field and i am listing all the 'contacts' per each financial year month using the field "SchduleDate".
The problem occurs when there ahve been no contacts for a certain month. If there have been no contacts for the month I would like my IIF statment to put a "0" in rather then just skip it.
Please find my sql below-Plaese can sombebody insert the if stament in the correct place within my statment below...
Sub Test_Reporta()
Dim AppExcel As Object
Dim LOCReport As Recordset
Dim LOCReport2 As Recordset
' Stops warnings from appearing
DoCmd.SetWarnings False
' ********************************************************************************************
Set AppExcel = CreateObject("excel.application")
AppExcel.Visible = True
' Opens Excel template
'Selects Specialty
Select Case [Forms]![Test]![lstSpecialty]
Case "DNU"
AppExcel.Workbooks.Open "C:\Documents and Settings\msundhu\Desktop\Copy of DNU Activity_Revised.xls", , True
Case Else
MsgBox "No Valid Specialty selected"
Exit Sub
End Select
'***********************************************************************************************
'Defines variable to queries records
'Extract all Referrals
AppExcel.StatusBar = "Running Referrals"
Select Case [Forms]![Test]![lstSpecialty]
Case "DNU"
AppExcel.StatusBar = "Group Contacts"
strSql = "SELECT dbo_vwSchedules.Service, Format([SchduleDate],""yyyymm"") AS [Date], Count(dbo_vwSchedules.SCHDL_REFNO) AS CountOfSCHDL_REFNO INTO tblGroupContacts " & vbCrLf & _
"FROM dbo_vwSchedules INNER JOIN dbo_tblSchedules ON dbo_vwSchedules.PARNT_REFNO = dbo_tblSchedules.SCHDL_REFNO " & vbCrLf & _
"WHERE (((dbo_vwSchedules.ServiceID) Like ""dnu"") AND ((dbo_tblSchedules.SATYP_REFNO) Like ""1452"") AND ((dbo_vwSchedules.SchduleDate) Between [forms]![Test]![txtStartDate] And [forms]![Test]![txtEndDate])) " & vbCrLf & _
"GROUP BY dbo_vwSchedules.Service, Format([SchduleDate],""yyyymm"");"
DoCmd.RunSQL strSql
Set LOCReport = CurrentDb.OpenRecordset("SELECT tblGroupContacts.Service, tblGroupContacts.Date, tblGroupContacts.CountOfSCHDL_REFNO FROM tblGroupContacts")
'selects named excel worksheet
Set datasheet = AppExcel.ActiveWorkBook.Sheets("RawData")
RepType = 1
Call Report_Run13(LOCReport, datasheet, RepType)
Many Thanks.....matthew
I am counting contacts through using the field "SCHDL_REFNO" as my count field and i am listing all the 'contacts' per each financial year month using the field "SchduleDate".
The problem occurs when there ahve been no contacts for a certain month. If there have been no contacts for the month I would like my IIF statment to put a "0" in rather then just skip it.
Please find my sql below-Plaese can sombebody insert the if stament in the correct place within my statment below...
Code:
Dim AppExcel As Object
Dim LOCReport As Recordset
Dim LOCReport2 As Recordset
' Stops warnings from appearing
DoCmd.SetWarnings False
' ********************************************************************************************
Set AppExcel = CreateObject("excel.application")
AppExcel.Visible = True
' Opens Excel template
'Selects Specialty
Select Case [Forms]![Test]![lstSpecialty]
Case "DNU"
AppExcel.Workbooks.Open "C:\Documents and Settings\msundhu\Desktop\Copy of DNU Activity_Revised.xls", , True
Case Else
MsgBox "No Valid Specialty selected"
Exit Sub
End Select
'***********************************************************************************************
'Defines variable to queries records
'Extract all Referrals
AppExcel.StatusBar = "Running Referrals"
Select Case [Forms]![Test]![lstSpecialty]
Case "DNU"
AppExcel.StatusBar = "Group Contacts"
strSql = "SELECT dbo_vwSchedules.Service, Format([SchduleDate],""yyyymm"") AS [Date], Count(dbo_vwSchedules.SCHDL_REFNO) AS CountOfSCHDL_REFNO INTO tblGroupContacts " & vbCrLf & _
"FROM dbo_vwSchedules INNER JOIN dbo_tblSchedules ON dbo_vwSchedules.PARNT_REFNO = dbo_tblSchedules.SCHDL_REFNO " & vbCrLf & _
"WHERE (((dbo_vwSchedules.ServiceID) Like ""dnu"") AND ((dbo_tblSchedules.SATYP_REFNO) Like ""1452"") AND ((dbo_vwSchedules.SchduleDate) Between [forms]![Test]![txtStartDate] And [forms]![Test]![txtEndDate])) " & vbCrLf & _
"GROUP BY dbo_vwSchedules.Service, Format([SchduleDate],""yyyymm"");"
DoCmd.RunSQL strSql
Set LOCReport = CurrentDb.OpenRecordset("SELECT tblGroupContacts.Service, tblGroupContacts.Date, tblGroupContacts.CountOfSCHDL_REFNO FROM tblGroupContacts")
'selects named excel worksheet
Set datasheet = AppExcel.ActiveWorkBook.Sheets("RawData")
RepType = 1
Call Report_Run13(LOCReport, datasheet, RepType)
Many Thanks.....matthew