Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refilering a form in VB

Status
Not open for further replies.

jordanh

Technical User
Nov 11, 2002
47
GB
Hi, I can't quite work out why something isnt working, so I just wondered if you guys could help me out.

I have a form displaying a record. Nothing strange there. The record is selected from the database and displayed in the form using a filter applied to the form, ie

criteria = "System=" & "'" & ...
DoCmd.OpenForm "browse_item"
Forms!browse_item.Filter = criteria
Forms!browse_item.FilterOn = True

I've been asked to put next and previous buttons on this form, and I can think of a fairly simple way to do it: remove the filter, build new criteria based on elements on the existing form, re-filter. It's not working though,. This is my code,
----------

Dim rR1, rR2, rR3, max As Integer
Dim criteria As String
rR1 = Forms!browse_item![RefR1]
rR2 = Forms!browse_item![RefR2]
rR3 = Forms!browse_item![RefR3]

max = DMax("[R3]", "Query1", "[R1] = " & rR1 & " AND [R2] = " & rR2)
R3 = R3 + 1
If R3 <= max Then
criteria = &quot;R1=&quot; & R1 & &quot; AND &quot; & &quot;R2=&quot; & R2 & &quot; AND R3=&quot; & R3
Else
R2 = R2 + 1
R3 = 0
criteria = &quot;R1=&quot; & R1 & &quot; AND &quot; & &quot;R2=&quot; & R2 & &quot; AND R3=&quot; & R3
End If

Forms!browse_item.FilterOn = False
Forms!browse_item.Filter = criteria
Forms!browse_item.FilterOn = True

------------------
It's attached to onclick of a button. When I click on the next button, the id fields (R1, R2 and R3) increment on screen but the other fields don't. Do I need to requry or something? There are about 100 fields on the sceen so putting in *.requery() for each one isn't really an option. Is there a 'requery all' or something? Or is requery not my problem?

Any help would be greatly appreciated, thanks in advance.

Jordan
 
If all you want to do is to put a next/previous button on the form, you don't have to worry about removing the filter, etc. Just use the wizard to create a command button. Under Categories, select Record Navigation. Under Actions select &quot;GoTo Next Record&quot; or &quot;GoTo Previous Record&quot;
 
creating the command button doesn't work as the form already has a filter applied to it, leaving a recordset consisting of one record. An acPrevious or acNext button simply says it's reached the end of records (which it has!).

It's OK now, if you look closely at the code above you'll see that in the criteria - where I'm inserting variables - I'm not actually inserting the variables I've set. Spelling error, plain and simple.

I've got it working fine now, and the back button, and it's quite a lot more sophisticated than than the code above.

Thanks for replying.

Jordan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top