Runtime error 2491 in a Navigation Form (1 Viewer)

annarocha

New member
Local time
Today, 04:47
Joined
May 5, 2016
Messages
6
I'm getting this error
**Run-time error 2491
The action or method is invalid because the form or report isn't bound to a table or query.

I'm using a search/filter in my form and it works fine. But once I added it to a Navigation form it is giving me the error.

This is the code I'm using.

Option Compare Database
Private Sub Searchbutton_Click()
'search button
Call Search
End Sub
Sub Search()
Dim strcriteria, task As String
Me.Refresh
If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "Please enter the date range", vbInformation, "Date Range Required"
Me.StartDate.SetFocus
Else
strcriteria = "([EffectiveDate] >= #" & Me.StartDate & "# And [EffectiveDate] <= #" & Me.EndDate & "#)"
task = "select * from Me.8CONST where(" & strcriteria & ") order by [EffectiveDate]"
DoCmd.ApplyFilter task

End If
End Sub


********

If anyone can help!

Thank you!
Anna
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,231
i think it has to do with your DoCmd.ApplyFilter.
is the form bound?
 

annarocha

New member
Local time
Today, 04:47
Joined
May 5, 2016
Messages
6
It is. But once you put it into the Navigation form it seems to lost something.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,231
how about not using filter, but instead change the rowsource of your form.
also you have error in "task" there:

task = "select * from " & Me.8CONST & " where (" & strcriteria & ") order by [EffectiveDate]"

me.recordsource = task
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,231
upload the db for us to see.
 

annarocha

New member
Local time
Today, 04:47
Joined
May 5, 2016
Messages
6
Ok. I did a small sample on my issue.
I was using a 5/1/16 to 5/31/16 for my sort dates. I should return 1 item.:banghead:.
I appreciate any help I can get!

Thank you!
Anna Rocha
 

Attachments

  • SampleDB.accdb
    616 KB · Views: 100

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:47
Joined
May 7, 2009
Messages
19,231
here is the fix, please review the code behind your search button click event.
 

Attachments

  • SampleDB.accdb
    644 KB · Views: 355

Users who are viewing this thread

Top Bottom