I am using Excel 2013 and Access 2013. My access query has a form that takes2 inputs, "start date" and "end date", and then runs a macro in access. Is there a way I can use VBA to input "start date" and "end date" from excel and run the form in access? Here is what I have tried, but I get an error saying "The action or method is invalid because the form or report isn't bound to a table or query"
Sub RunAccessQuery()
Dim strDatabasePath As String
Dim appAccess As Access.Application
Dim startDate As Date
Dim endDate As Date
startDate = ThisWorkbook.Sheets("sheet1").Range("B2").Value
strDatabasePath = "access database path"
Set appAccess = New Access.Application
With appAccess
Application.DisplayAlerts = False
.OpenCurrentDatabase strDatabasePath
.DoCmd.OpenForm "inputForm", , , "start =" & startDate
'.Quit
End With
Set appAccess = Nothing
ThisWorkbook.RefreshAll
MsgBox ("Data has been updated")
End Sub
This is what my form looks like. Click me runs a macro, the first text box holds variable "start" and second one holds variable "end"
.Visible = True
. However, the form is not filtered to the desired record until I change code to:"start = #" & startDate & "#"
. What is the form's RecordSource - a table, query, SQL statement? – June7