Open Form to Specific Record

DanG

Registered User.
Local time
Today, 02:21
Joined
Nov 4, 2004
Messages
477
Hello,

The code below opens "frmMSREntry" to a matching "MSRID" field from "frmsearchcentral" and closes "frmsearchcentral". Seems simple enough, but once I'm in the desired MSRID and want to move to the next record I get an error saying I can not move to the specified record. So I am stuck in the current record and can't move forward or back.

Is there anyway to release the grip on the current MSRID? :confused:

Thank you in advance

Code:
Private Sub GoToMSR_Click()
On Error GoTo Err_GoToMSR_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmMSREntry"
  
    stLinkCriteria = "[MSRID]=" & Me![MSRID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    DoCmd.Close acForm, "frmsearchcentral"

Exit_GoToMSR_Click:
    Exit Sub

Err_GoToMSR_Click:
    MsgBox Err.Description
    Resume Exit_GoToMSR_Click
    
End Sub
 
If you want to keep your exising code, you will need to manually rempve the filter to be able to see all the records.


You could change the code to not use a filter, by find the desired record after the form has bw opened.

Something like:
Code:
Private Sub GoToMSR_Click()
On Error GoTo Err_GoToMSR_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmMSREntry"
  
'''    stLinkCriteria = "[MSRID]=" & Me![MSRID]
'''    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
   DoCmd.OpenForm stDocName

    DoCmd.SelectObject A_FORM, stDocName
    DoCmd.GoToControl "MSRID"
    DoCmd.FindRecord Me.[MSRID], A_ENTIRE, False, acSearchAll, False, A_CURRENT

    DoCmd.Close acForm, "frmsearchcentral"

Exit_GoToMSR_Click:
    Exit Sub

Err_GoToMSR_Click:
    MsgBox Err.Description
    Resume Exit_GoToMSR_Click
    
End Sub
 
Wierd, I didn't realize that the VBA was a "filter", but tried to "remove filter" on the record while I was in it and it didn't do anything. :confused:

Anyhow, what yo say makes sence and I will give it a go soon and get back to you.

Thank you very much for your help!
 
Worked perfect!

I couldn't find much on google about the A_Form is it possible for you to explain?

Again thank you very much.
 
A_Form and acForm (newer) are constants with the the same vaule. The A_FORM was used with Access 2.0. A different naming convetion for constants was introduced in a newer version and has been changed to be acForm. The code example I post was from code I have been using since Access 2.0. I have not changed it because it allows the code to work with the as many version of Access as possible.



Example:
Code:
? acForm
 2 
? A_FORM
 2
 

Users who are viewing this thread

Back
Top Bottom