GoToRecord acCurrent??

  • Thread starter Bradley C. Hammerstrom
  • Start date
B

Bradley C. Hammerstrom

Access200 DAO

I'm still working on this. Whether a form is loaded or closed, view the same
record. I got the DoCmd.OpenForm part to work.
Now, how do I GoTo the same record in another loaded form?

***********************
Private Sub cmdGoToMain_Click()
Dim strFormName As String
Dim intRecNumber As Integer
Dim strPhotoRecord As String
strFormName = "frmMain"
intRecNumber = Me.Bookmark '(Type Mismatch)
strPhotoRecord = Me.PhotoID

If IsLoaded(strFormName) Then
'Go to same photo
DoCmd.GoToRecord acDataForm, strFormName, acGoTo, intRecNumber
Else
'Open the PhotoBook form and go to same photo
DoCmd.OpenForm strFormName, , , OpenArgs:=strPhotoRecord
End If

End Sub
*************************
Bookmark is a string. I need a number for the offset argument that is
acCurrent.

Very confused.
Brad H.
 
B

Bruce M. Thompson

I'm still working on this. Whether a form is loaded or closed, view the same
record. I got the DoCmd.OpenForm part to work.
Now, how do I GoTo the same record in another loaded form?
<snip>

You can open the form to *only* the desired record by implementing the
"WhereCondition" argument of the "OpenForm" method:

'**
DoCmd.OpenForm strFormName,,,"PhotoID =""" & strPhotoRecord & """"
'**

If you want to apply the filter to another form (containing records from the
same table) to display the current record as you scroll through the records in
the first form, you can use the following code in the form's "On Current" event
procedure:

'**
Forms("YourFormName").Filter = "PhotoID =""" & strPhotoRecord & """"
Forms("YourFormName").FilterOn = True
'**

You can remove/re-enable the filter anytime after opening the second form or
setting its filter simply by clicking on the "Add/Remove Filter" button on the
"form view" commandbar while the form has the focus or, using VBA, by setting
the form's ".FilterOn" property to true or false.
 
B

Bradley C. Hammerstrom

Bruce, thanks for the reply.
Bruce M. Thompson, Microsoft Access MVP wrote:
You can open the form to *only* the desired record by implementing the
"WhereCondition" argument of the "OpenForm" method:

Yes, but I didn't mention that the second form is in Datasheet view, and I
need the user to see all records before and after, and to scroll through
them. So a filter which displays *only* the desired record will not be
optimal. Besides, as I believe I posted, I actually have the OpenArgs of the
OpenForm method working for me to open the form (if it's closed) and go to
the record. But what I am missing is a GoToRecord method that will (If the
second form is already open) simply go to the matching record as in the
first form.
. . .to display the current record as you scroll through the records in
the first form, you can use the following code in the form's "On Current" event
procedure:

This technique will be cumbersome because each record loads an image
control. So I would rather load the image (i.e. change the record) on the
second form only as the user needs it (click the command button).

Can this code be made to work to go to the same record number as on the
first form?
DoCmd.GoToRecord acDataForm, strFormName, acGoTo, intRecNumber

Brad H.
 
B

Bruce M. Thompson

Okay, Brad, I see where you are coming from. If you use the following to open
the second form ...

DoCmd.OpenForm strFormName, , , OpenArgs:=strPhotoRecord

.... you can add this code to the second form's "On Open" event procedure:

'**If OpenArgs contains a value, then goto the specified record
If Len(Trim(Me.OpenArgs) & vbNullString) > 0 Then
Me.Recordset.Findfirst "PhotoID=" & Me.OpenArgs
End If
'**

I hope this gets you started.
 
B

Bradley C. Hammerstrom

Bruce,

I think I am only confusing you, sorry.
Let's forget about opening the second form. Let's suppose both forms are
*already opened*. Already Loaded.

The user is viewing a record on the first form that he wants to view more
detail in the second form (frmMain), so the user clicks a command button
(cmdGoToMain), and the *already open* second form goes to the same record. I
can use the Visible property to make the forms show when I want to, I just
need the second form to go to the same record.

Here is what I have in mind:
****************
Private Sub cmdGoToMain_Click()
Dim strFormName As String
Dim intRecNumber As Integer
strFormName = "frmMain"
intRecNumber = Me.Bookmark

DoCmd.GoToRecord acDataForm, strFormName, acGoTo, intRecNumber

End Sub
***************
I hope this is clearer.
Brad H.
 
B

Bruce M. Thompson

I think I am only confusing you, sorry.
Let's forget about opening the second form. Let's suppose both forms are
*already opened*. Already Loaded.

Maybe the confusion was already there. said:
The user is viewing a record on the first form that he wants to view more
detail in the second form (frmMain), so the user clicks a command button
(cmdGoToMain), and the *already open* second form goes to the same record. I
can use the Visible property to make the forms show when I want to, I just
need the second form to go to the same record.

Here is what I have in mind:
****************
Private Sub cmdGoToMain_Click()
Dim strFormName As String
Dim intRecNumber As Integer
strFormName = "frmMain"
intRecNumber = Me.Bookmark

DoCmd.GoToRecord acDataForm, strFormName, acGoTo, intRecNumber

End Sub
***************
I hope this is clearer.

Yes. I would still use the ".FindFirst" method - I generally don't rely on the
bookmark property between forms:

'*********
Dim strFormName As String
Dim strPhotoRecord As String
strFormName = "frmMain"
strPhotoRecord = Nz(Me.PhotoID, "")

'Make *sure* the target form is loaded
If Application.CurrentProject.AllForms(strFormName).IsLoaded Then
Forms(strFormName).Recordset.FindFirst _
"PhotoID=""" & strPhotoRecord & """"
Else
MsgBox "The Main form is not open."
End If
'*********
 

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

Top