Need help with VBA action

Zaides

New member
Local time
Today, 05:08
Joined
Mar 2, 2019
Messages
4
I am in need of experienced eyes to make sense to why my VBA expression does not work :banghead:. I am attempting to string together three different query filters, that work correctly individually, to a command button. The three working expressions are:
  • [PostMailingFilterQry]![PostName] Like "*" & [Forms]![DashboardFrm]![PostNameAdvSrchByPostcbo]
  • [PostMailingFilterQry]![TypeOfWorkReceived] Like "*" & [Forms]![DashboardFrm]![WorkTypeAdvSrchByPostcbo] & "*"
  • [PostMailingFilterQry]![DateMailedFromPost] Between [Forms]![DashboardFrm]![FromAdvSrchByPosttxt] And [Forms]![DashboardFrm]![ToAdvSrchByPosttxt]

My failing VBA code:

Private Sub AvancedSearchMailedByPostcmd_Click()
'[docmd].OpenQuery (PostMailingFilterQry, [acViewNormal], [acReadOnly])
'[docmd].ApplyFilter [PostMailingFilterQry]![PostName] Like "*" & [Forms]![DashboardFrm]![PostNameAdvSrchByPostcbo] & "*" & [PostMailingFilterQry]![TypeOfWorkReceived] Like "*" & [Forms]![DashboardFrm]![WorkTypeAdvSrchByPostcbo] & "*" & [PostMailingFilterQry]![DateMailedFromPost] Between [Forms]![DashboardFrm]![FromAdvSrchByPosttxt] And [Forms]![DashboardFrm]![ToAdvSrchByPosttxt]
End Sub

Any help would be appreciated!
 
Have a look at the video on my website here:- where I demonstrate how I have handled filters in the past. Basically you create them in the form then copy them out and call them with VBA code.

ApplyFilter to Sub-Form
 
This was helpful Gizmo! It got me here but still telling me an error is occuring

Private Sub AvancedSearchMailedByPostcmd_Click()
[DoCmd].OpenQuery(PostMailingFilterQry, , [acReadOnly]) = Me.Filter = "([PostMailingFilterQry].[PostName]= '[Forms]![DashboardFrm]![PostNameAdvSrchByPostcbo]')" And "([PostMailingFilterQry].[TypeOfWorkReceived]= '[Forms]![DashboardFrm]![WorkTypeAdvSrchByPostcbo]')" And "([PostMailingFilterQry].[DateMailedFromPost]= ' Between '[Forms]![DashboardFrm]![FromAdvSrchByPosttxt] And [Forms]![DashboardFrm]![ToAdvSrchByPosttxt]') "

End Sub


The error is around here: AvancedSearchMailedByPostcmd_Click()
[DoCmd].OpenQuery(PostMailingFilterQry, , [acReadOnly])
 

Users who are viewing this thread

Back
Top Bottom