Solved Search Bij Date on Split form (1 Viewer)

Rania01

Member
Local time
Today, 05:13
Joined
Oct 9, 2021
Messages
34
Dear All,

With this vba I try to do a search with the date I get an error
What mistakes did I make
I use below VBA

Code:
Private Sub cmdSearch_Click()
Call Search
End Sub

Sub Search()
Dim strCriteria, task As String

Me.Refresh

If IsNull(Me.followupFrom) Or IsNull(Me.followupTo) Then
MsgBox "Enter date", vbInformation, "Date Range Required"
Me.followupFrom.SetFocus

Else

strcreteria = "([follow up] >= #" & Me.followupFrom & "# And [follow up] <= #" & Me.followupTo & "#)"
task = "Select * from qrySearch where (" & strCriteria & ") order by [follow_up]"

DoCmd.ApplyFilter task

End If

End Sub
 

Attachments

  • Search.png
    Search.png
    74.8 KB · Views: 302

Gasman

Enthusiastic Amateur
Local time
Today, 04:13
Joined
Sep 21, 2011
Messages
10,853
You need Option Explicit at the top of ALL your modules.
strcreteria =
& strCriteria &

Do yourself a favour and add
Debug.Print strCriteria before you try and use it.
 

Rania01

Member
Local time
Today, 05:13
Joined
Oct 9, 2021
Messages
34
You need Option Explicit at the top of ALL your modules.
strcreteria =
& strCriteria &

Do yourself a favour and add
Debug.Print strCriteria before you try and use it.
Hello Gasman,
I get error variable not defined
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:13
Joined
Sep 21, 2011
Messages
10,853
Hello Gasman,
I get error variable not defined
Yes, I would expect that. :(
So make the names the same, that is strCriteria

Computers are stupid, they do not recognise spelling mistakes, but you need to, else coding is not for you?
The Option Explicit will help you identify those spelling errors.
To have it added automatically for new modules go to the VBA window and Tools/Options and the Editor tab. make sure Require variable Declaration is ticked. You will need to add it to existing modules already created. :(

Also you need to assign each variable a type .
Code:
Dim strCriteria, task As String

strCriteria is a Variant, and only Task is a string as you have declared them there. :(

You need
Dim strCriteria As String, Task As String
 

Rania01

Member
Local time
Today, 05:13
Joined
Oct 9, 2021
Messages
34
Yes, I would expect that. :(
So make the names the same, that is strCriteria

Computers are stupid, they do not recognise spelling mistakes, but you need to, else coding is not for you?
The Option Explicit will help you identify those spelling errors.
To have it added automatically for new modules go to the VBA window and Tools/Options and the Editor tab. make sure Require variable Declaration is ticked. You will need to add it to existing modules already created. :(

Also you need to assign each variable a type .
Code:
Dim strCriteria, task As String

strCriteria is a Variant, and only Task is a string as you have declared them there. :(

You need
Dim strCriteria As String, Task As String
I get error variable not defined

Code:
Sub Search()
Dim strCriteria As String, Task As String
Me.Refresh

If IsNull(Me.followupFrom) Or IsNull(Me.followupTo) Then
MsgBox "Enter date", vbInformation, "Date Range Required"
Me.followupFrom.SetFocus

Else

strcreteria = "([follow_up] >= #" & Me.followupFrom & "# And [follow_up] <= #" & Me.followupTo & "#)"
Task = "Select * from qrySearch where (" & strCriteria & ") order by [follow_up]"

DoCmd.ApplyFilter Task

End If

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:13
Joined
Sep 21, 2011
Messages
10,853
And what variable is that? :(
 

Users who are viewing this thread

Top Bottom