Hi,
Currently when i run my vba it populates my excel spreadsheet fine. The only problem being if there is no data within a month in my access table it wont recognise it and will just populate the the excel spreadsheet not reading the month.
for example if my access atble dosnt have a july 09-it wont recogise this when it populates my excel spreadsheet wit will just put august09s data in the july field pleaes find nmy statment below..
I am not very good with VB so help would be great...!!!
###################################################################
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 = "Running Referrals"
###################################################################
ppExcel.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)
###################################################################
Public Sub Report_Run13(LOCReport As Recordset, datasheet As Variant, RepType As Integer) 'Group Contacts'
Dim AppExcel As Object
Dim CurrentPG As String
Dim CurrentSheet As Variant
Dim SPos As Integer
Dim rpos As Integer
Dim cpos As Integer
Dim overeight As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim x As Integer
Dim y As Integer
Dim count As Integer
Dim Test As Variant
Dim Test2 As Variant
Dim Test3 As Variant
Dim StartDate As Date
Dim EndDate As Date
Dim NewDate As Date
Dim SumTotal As Single
Dim PG As String
' Start position of report data
rpos = 7
cpos = 2
' For 12 month reports
If RepType = 2 Then
End If
' Sets read start to begining of record
LOCReport.MoveFirst
' Counts number of fields in record
j = LOCReport.Fields.count
Select Case [Forms]![Test]![lstSpecialty]
Case "DNU"
k = 37
End Select
Test2 = LOCReport.Fields(1).Name
Test3 = LOCReport.Fields(2).Name
' Reads data from query and transfers it to spreadsheet
While Not LOCReport.EOF
' allocating reference cells for month and count
For y = 3 To 14
'field0=service, field1=date, field2=countofrefno from dnureferals table
'allocated refernce cells for values..y=coulmn and '7' & '8'= rows
datasheet.Cells(45, y).Value = LOCReport.Fields(1)
datasheet.Cells(46, y).Value = LOCReport.Fields(2)
'datasheet.Cells(8, y).Interior.ColorIndex = k
'
LOCReport.MoveNext
Next y
Wend
LOCReport.Close
End Sub
###################################################################
Currently when i run my vba it populates my excel spreadsheet fine. The only problem being if there is no data within a month in my access table it wont recognise it and will just populate the the excel spreadsheet not reading the month.
for example if my access atble dosnt have a july 09-it wont recogise this when it populates my excel spreadsheet wit will just put august09s data in the july field pleaes find nmy statment below..
I am not very good with VB so help would be great...!!!
Code:
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 = "Running Referrals"
###################################################################
ppExcel.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)
###################################################################
Public Sub Report_Run13(LOCReport As Recordset, datasheet As Variant, RepType As Integer) 'Group Contacts'
Dim AppExcel As Object
Dim CurrentPG As String
Dim CurrentSheet As Variant
Dim SPos As Integer
Dim rpos As Integer
Dim cpos As Integer
Dim overeight As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim x As Integer
Dim y As Integer
Dim count As Integer
Dim Test As Variant
Dim Test2 As Variant
Dim Test3 As Variant
Dim StartDate As Date
Dim EndDate As Date
Dim NewDate As Date
Dim SumTotal As Single
Dim PG As String
' Start position of report data
rpos = 7
cpos = 2
' For 12 month reports
If RepType = 2 Then
End If
' Sets read start to begining of record
LOCReport.MoveFirst
' Counts number of fields in record
j = LOCReport.Fields.count
Select Case [Forms]![Test]![lstSpecialty]
Case "DNU"
k = 37
End Select
Test2 = LOCReport.Fields(1).Name
Test3 = LOCReport.Fields(2).Name
' Reads data from query and transfers it to spreadsheet
While Not LOCReport.EOF
' allocating reference cells for month and count
For y = 3 To 14
'field0=service, field1=date, field2=countofrefno from dnureferals table
'allocated refernce cells for values..y=coulmn and '7' & '8'= rows
datasheet.Cells(45, y).Value = LOCReport.Fields(1)
datasheet.Cells(46, y).Value = LOCReport.Fields(2)
'datasheet.Cells(8, y).Interior.ColorIndex = k
'
LOCReport.MoveNext
Next y
Wend
LOCReport.Close
End Sub
###################################################################