Hello, I have created a form with Option buttons![]()
Name: Capture.JPG Views: 13 Size: 30.3 KB ID: 18330" class="thumbnail" style="float:CONFIG" /> and have written the initial code for the buttons and tested with a msgbox to ensure all the buttons worked. Now i want to set up the each button to run a query which would pull the date range from the vba to use in the query. The query is setup to pull certain suppliers based a data range like 1/1/14 to 1/31/14. So the query for button one would pull the data based on January. The VBA sets up the year (so it is dependent on the current year so the code does not have to be updated each year) and puts it into 2 values. Now I need to be able to call the query and use the date range from the VBA.
Code:
Private Sub JanMissed()
Dim JanDate As Date
Dim DDate As Date
Dim CYear As Date
Dim MMonth As String
Dim sfile As String
Dim UserNameWindows As String
Dim BMonth As Date
Dim EMonth As Date
Dim objXLApp As Object
Dim XLApp As Object
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
Set dbf = dbs.QueryDefs("agry CT Missed ATT")
UserNameWindows = VBA.Environ("USERNAME")
DDate = Date
CYear = Year(DDate)
MMonth = "01 Jan"
BMonth = "1/1/" & CYear
EMonth = "1/31" & CYear
sfile = "C:\Users\" & UserNameWindows & "\Desktop\Export\" & MMonth & " Missed CT's.xlsx"
MsgBox ("I will now look for Missed Cycle Times's for January" & vbNewLine & vbNewLine & Time)
qdf.Parameters("Cx End Date").Value = BMonth
DoCmd.OpenQuery "aqry CT Missed ATT"
'DoCmd.OpenQuery "aqry CT Missed Sprint"
'DoCmd.OpenQuery "aqry CT Missed Sprint 65MHz"
'DoCmd.OpenQuery "aqry CT Missed TMO"
'DoCmd.OpenQuery "aqry CT Missed VZW"
' If DCount("*", "tbl CT Missed") <> 0 Then
' DoCmd.TransferSpreadsheet acExport, 10, "tbl CT Missed", sfile, True, "Missed CTs"
'End If
MsgBox (MMonth & " Missed CT's.xlsx is in the Export folder on your desktop." & _
vbNewLine & sfile & vbNewLine & Time)
Set XLApp = CreateObject("Excel.Application")
With XLApp
.Application.Visible = True
.UserControl = True
.Workbooks.Open "C:\Users\" & UserNameFunction & "\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL .xlsb", True
.Workbooks.Open sfile, False
.Run "PERSONAL.xlsb!Missed_CTs"
End With
Set XLApp = Nothing
End Sub