Hello everyone.
I have a new project that my supe wants in access rather than excel. I am comfortable writing code in excel. However, I am a little shaky on building DBs let alone using VBA. WTH I will learn. So I have to build a two-table database that then uses queries to produce paired down reports based on the tables in excel. I have uploaded the data from excel into Access and I have written the queries so that I get the results I expect. I have finally created a form that will utilize a text box to capture the fiscal year, and two separate list boxes (one for fiscal quarter and one for month). Once those are completed the user would then push a corresponding button to run one of three reports (monthly, quarterly or annually).
I am now on the whole on button click do portion of the database creation.
I want the button to launch the code that will create an excel document, check if there are four (4) worksheets and name them accordingly (create sheets if needs be), and based on the information provided on the user form (in access) amend the queries to pull the appropriate data and place in excel. then there are some formatting issues that will need to be addressed before saving.
here is the code for the user form (on button click or enter)
here is what I have been playing with for code in the module of access
I get a run time error '91' when I try and run the code (section of code is between the '&&& lines.
I look forward to learning more about VBA in access and access in general, but I really need to figure this out.
Thanks in advance
rich
I have a new project that my supe wants in access rather than excel. I am comfortable writing code in excel. However, I am a little shaky on building DBs let alone using VBA. WTH I will learn. So I have to build a two-table database that then uses queries to produce paired down reports based on the tables in excel. I have uploaded the data from excel into Access and I have written the queries so that I get the results I expect. I have finally created a form that will utilize a text box to capture the fiscal year, and two separate list boxes (one for fiscal quarter and one for month). Once those are completed the user would then push a corresponding button to run one of three reports (monthly, quarterly or annually).
I am now on the whole on button click do portion of the database creation.
I want the button to launch the code that will create an excel document, check if there are four (4) worksheets and name them accordingly (create sheets if needs be), and based on the information provided on the user form (in access) amend the queries to pull the appropriate data and place in excel. then there are some formatting issues that will need to be addressed before saving.
here is the code for the user form (on button click or enter)
Code:
Option Compare Database
Option Explicit
Private Sub CMDBAnnual_Click()
Call annual_report
End Sub
Private Sub CMDBAnnual_Enter()
Call annual_report
End Sub
Private Sub CMDBmonth_Click()
Call Monthly_report
End Sub
Private Sub CMDBmonth_Enter()
Call Monthly_report
End Sub
Private Sub CMDBqrtly_Click()
Call Quarterly_Report
End Sub
Private Sub CMDBqrtly_Enter()
Call Quarterly_Report
End Sub
here is what I have been playing with for code in the module of access
Code:
Option Compare Database
Option Explicit
Dim dbRECON As Database
Dim dbPATH As String
Dim oEXCEL As Object
Dim oWB As Object
'**************************************************************************************
'Header label called LBLtopheader
'1st subheader called LBLsubheaderleft
'2nd subheader called LBLsubheaderright
'
'report form called "Report Form"
'
'1st query called "DCAS Data FY 2015 Query"
'
'2nd query called "DCAS Detail Monthly Query" ** need this for DCAS detail for 3rd
'excel tab
'
'3rd query called "DCAS Monthly Total Query" ** need this for DCAS summary 2nd excel
'tab
'
'4th query called "EBAS Data FY 2015 Query"
'5th query called "EBAS Detail Monthly Total Query"
'7th query called "EBAS Detail no zero value Query" **need this for upper detail
'of 4th excel tab
'
'7th query called "EBAS Detail zero value Query" **need this for lower detail of 4th
'excel tab
'
'8th query called "EBAS Monthly Total Query" ** need this for EBAS summary 2nd excel
'tab
'**************************************************************************************
Public Sub annual_report()
Set dbRECON = Application.CurrentDb
dbPATH = Application.CurrentProject.Path
Set oEXCEL = CreateObject("Excel.application")
oEXCEL.Application.ScreenUpdating = False
oEXCEL.Visible = True
DoCmd.OpenForm "reportform"
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
oWB.Name = "2612 DCAS to EBAS-TJS " & Forms("ReportForm")!TXTannual.Value
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
' text box called TXTannual set variable to TXTannual.value
End Sub
Private Sub Monthly_report()
Set dbRECON = Application.CurrentDb
dbPATH = Application.CurrentProject.Path
MsgBox dbPATH
' list box called LISTmonth set variable to LISTmonth.value
End Sub
Private Sub Quarterly_Report()
Set dbRECON = Application.CurrentDb
dbPATH = Application.CurrentProject.Path
' list box called LISTqrtly set variable to LISTqrtly.value
End Sub
I get a run time error '91' when I try and run the code (section of code is between the '&&& lines.
I look forward to learning more about VBA in access and access in general, but I really need to figure this out.
Thanks in advance
rich