Solved Open form to specific record but allow record navigation. (1 Viewer)

ddewald

New member
Local time
Today, 16:01
Joined
Jan 31, 2020
Messages
19
Hello all. I have a form called "EditVendor" that allows you to edit a vendors details and I have a button called "SaveAndClose" that closes the form and opens up another form and goes to the same record. Heres the code (I know my names are sloppy):

DoCmd.OpenForm "frm_Vendors", , , "[VendorID]=" & Nz(Me![VendorID], 0)

It works great, but it of course filters the opened form and it wont allow you to flip through records in Navigation. I know if I just click the filtered button it will allow it but the people using the form will not. Any work arounds out there?
 

ddewald

New member
Local time
Today, 16:01
Joined
Jan 31, 2020
Messages
19
Is there a way to build that command into the openform command?
 

ddewald

New member
Local time
Today, 16:01
Joined
Jan 31, 2020
Messages
19
Figured it out. May be a bit sloppy but I put this code into the forms Resize event.

Dim intID As Integer
Dim rs As Object
intID = Me.VendorID
Me.FilterOn = False
Set rs = Me.RecordsetClone
With rs
.FindFirst "[VendorID]=" & intID
Me.Bookmark = .Bookmark
End With
rs.Close

Removed the filter while staying on the same record.
 

vba_php

Forum Troll
Local time
Today, 15:01
Joined
Oct 6, 2019
Messages
2,880
well good. mark this thread as solved then if you would. thanks!
 

isladogs

MVP / VIP
Local time
Today, 21:01
Joined
Jan 14, 2017
Messages
18,261
Can I suggest a different approach. Open the form to the full recordset.
Use a combo to select a specific record and set FilterOn=True.
Next to the combo have a button to clear the filter and show all records again
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:01
Joined
May 21, 2018
Messages
8,605
You can also pass in the filer via openargs in the domcd.openform if opened ACDIALOG.
Then in the forms load event
Code:
if not trim(me.openargs & "") = "" then
me.recordset.findfirst "SomeField = " & me.openargs 'wrap in single quotes if a string
end if
If not opened acdialog then after the openform simply move to that record.
forms("calledformname").recordset.findfirst "somefield = " & some value 'wrap in single quotes if text.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:01
Joined
Feb 19, 2002
Messages
43,484
Just FYI, if your BE is Jet/ACE what you are doing doesn't matter but since almost all of my apps are either designed for SQL Server (or other RDBMS) or get upsized later, I NEVER use form filters since that eliminates any benefit you get from using a "real" RDBMS as your BE and is the primary reason why most people are appalled by how slow their formerly speedy app is when they switch from Jet/ACE to SQL Server.

If you are using SQL Server, let us know and I'll be more specific on how I handle this.
 

Users who are viewing this thread

Top Bottom