Finding a feild

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My fields are set up by Section, Township and Range. When I press the find
button I am only allowed to search in one feild such as Section. My question
is, is it possible to search in all the 3 fields at the same time? If i want
to look for Section 1, Township 54, and Range 2...how can i insert that data
to obtain the certain information? All help is much appreciated. Thank you.
 
My fields are set up by Section, Township and Range. When I press the find
button I am only allowed to search in one feild such as Section. My question
is, is it possible to search in all the 3 fields at the same time? If i want
to look for Section 1, Township 54, and Range 2...how can i insert that data
to obtain the certain information? All help is much appreciated. Thank you.

You'll need just a little bit of VBA code to do this.

One way would be to use a Form (you should NOT be working directly in
tables!) based on the table to display the information that you want
to see.

In the form's Header, you could put three unbound (nothing in the
COntrol Source) controls (I'd use Combo Boxes with the valid sections,
townships and ranges in their row sources); let's call them cboSec,
cboTwp, cboRng. Also put a command button, named cmdShow let's say. In
its Click event select the ... icon, and choose Code Builder; put in
code like

Private Sub cmdShow_Click()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone ' get the Form's recordset
rs.FindFirst "[Section] = " & Me!cboSec & _
" AND [Township] = " & Me!cboTwp & _
" AND [Range] = " & Me!cboRng
If rs.NoMatch Then
' this combination isn't in the form's recordsource
MsgBox "Sorry, you're off the map!"
Else
' if it is in the recordsource, jump to the record
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing 'clean up after yourself
End Sub


John W. Vinson[MVP]
 
Bam11 said:
My fields are set up by Section, Township and Range. When I press the
find button I am only allowed to search in one feild such as Section.
My question is, is it possible to search in all the 3 fields at the
same time? If i want to look for Section 1, Township 54, and Range
2...how can i insert that data to obtain the certain information? All
help is much appreciated. Thank you.

Are you using a form or a query?

It is easy to do complex searches like you are talking about in a query.
 
I am not sure what facilities exist in which versions of Access.
Find the first field.
Apply a filter
Find the second field
apply another filter (may be version dependent, I cannot remember)

If you cannot add more filters then sort on one of the other search fields,
and the required record should be easy to find.


John Vinson said:
My fields are set up by Section, Township and Range. When I press the find
button I am only allowed to search in one feild such as Section. My
question
is, is it possible to search in all the 3 fields at the same time? If i
want
to look for Section 1, Township 54, and Range 2...how can i insert that
data
to obtain the certain information? All help is much appreciated. Thank
you.

You'll need just a little bit of VBA code to do this.

One way would be to use a Form (you should NOT be working directly in
tables!) based on the table to display the information that you want
to see.

In the form's Header, you could put three unbound (nothing in the
COntrol Source) controls (I'd use Combo Boxes with the valid sections,
townships and ranges in their row sources); let's call them cboSec,
cboTwp, cboRng. Also put a command button, named cmdShow let's say. In
its Click event select the ... icon, and choose Code Builder; put in
code like

Private Sub cmdShow_Click()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone ' get the Form's recordset
rs.FindFirst "[Section] = " & Me!cboSec & _
" AND [Township] = " & Me!cboTwp & _
" AND [Range] = " & Me!cboRng
If rs.NoMatch Then
' this combination isn't in the form's recordsource
MsgBox "Sorry, you're off the map!"
Else
' if it is in the recordsource, jump to the record
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing 'clean up after yourself
End Sub


John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top