Code:
Option Compare Database
Option Explicit '<< MISSING - should be in EVERY code module
'------------------------------------------------------------
' Macro2
'
'------------------------------------------------------------
Function Macro2()
On Error GoTo Macro2_Err
DoCmd.OpenQuery "WeekView", acViewNormal, acEdit
' DoCmd.SearchForRecord acQuery, "WeekView", acFirst, "[WeekView]![Weekday]=3" '<<-- ERROR
DoCmd.SearchForRecord acDataQuery, "WeekView", acFirst, "[Weekday]=3"
DoCmd.FindRecord "[Task Defenition]", acEntire, True, , True, acCurrent, True
' DoCmd.BrowseTo acForm, "WeekView Form", "", "[Tuesday Tasks]=""[WeekView]![Task Defenition]""", "1", 0 '<<-- ERROR
DoCmd.BrowseTo acBrowseToForm, "WeekView Form", "", "[Tuesday Tasks]= '" & [WeekView]![Task Defenition] &"'", , acFormAdd
DoCmd.GoToControl "[Tuesday Tasks]"
DoCmd.RunCommand acCmdSaveRecord 'nothing has changed, don't know why this command is here
DoCmd.RunCommand acCmdRemoveFilterSort
' Exit Function '<-not needed - the next command following this line is the Exit Function command.
Macro2_Exit:
Exit Function
Macro2_Err:
' MsgBox Error$
MsgBox Err.Description
Resume Macro2_Exit
End Function
Well, you can see the errors.
In the line " DoCmd.SearchForRecord",
the argument "acQuery" should be "acDataQuery"
In the line " DoCmd.BrowseTo",
the argument "acForm" should be "acBrowseToForm"
for the WHERE argument, you need to concatenate the value to the field name.
you have "1" for the "PAGE" argument. But this argument is Web only!
Also, the BROWSETO command loads an object into a sub form control... but the path is not specified
I would have used a sub - you are not returning a value.....
Don't understand what you are trying to do with this function.
You open a query
-You search for a record (DoCmd.SearchForRecord)
-Then you find a record (DoCmd.FindRecord)
-Next, DoCmd.BrowseTo (try to open an object in a sub form control)
-You go to a control
-You save the record (apparently without adding/editing the record)
-You remove a filter/sort
(But you never close the query.....)
Then end the function.........