Simple GoToRecord Question

NicholasP

Active Member
Joined
Nov 18, 2006
Messages
291
Hi,

I'm trying to use GoToRecord -- instead of using the filter on the OpenForm cmd (I want the user to be able to scroll through adjacent records without having to close the new form and reclick on a record).

The problem seems to be that the form is opening, and then the code is not progressing to the GotoRecord line. Instead the form is opening up to the first record in the set (natually). Is there something simple I'm missing here?

Any help would be greatly appreciated!

Thanks
Nick


Code:
Dim R As Long
R = Me.CurrentRecord

DoCmd.OpenForm ("Individual Info"), , , , , acDialog
DoCmd.GoToRecord acDataForm, "Individual Info", acGoTo, R
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Because you open the form as a dialog box, no more code is executed until you either close the form, or set it to .Visible = False.
So, if you want to go to record number "R", then you will have to put that code into the "Indivisual Info" form's OnLoad event. When you open a form you can pass a parameter to it, then you can use Me.OpenArgs to retrieve that parameter in the form you just opened.
HTH,
 
Upvote 0
Vic,

I've been researching OpenArgs quite a bit, but I can't seem to make it work for my application. Most of the examples I've been able to find use OpenArgs in docmd.OpenForm or they use OpenArgs to reference a field.

However, I'm using it to reference a record number and I'm unsure of how to correctly reference a record number

The way that I envision using the OpenArgs property would be something like (and this code currently doesn't work):

Code:
Private Sub Form_DblClick(Cancel As Integer)

Dim R As Long 
R = Me.CurrentRecord 
R = Me.Form("individual info").R.OpenArgs
DoCmd.OpenForm ("Individual Info"), , , , , acDialog

Exit Sub


Private Sub Form_Load()

R = Me.OpenArgs

DoCmd.GoToRecord acDataForm, "Individual Info", acGoTo, R

End Sub


Would you be so kind as to point out where I'm going wrong in my application of the OpenArgs property? More than anything, I'm interested in learning how to use it (something new is always good!)

Thanks Again
Nick
 
Upvote 0
Looks like you are very close. I changed only two lines. I commented out two and added one.
Code:
Private Sub Form_DblClick(Cancel As Integer) 

Dim R As Long 
R = Me.CurrentRecord 
'    *** not needed ***   R = Me.Form("individual info").R.OpenArgs 
'     DoCmd.OpenForm ("Individual Info"), , , , , acDialog 
DoCmd.OpenForm ("Individual Info"), , , , , acDialog , R


Exit Sub 


Private Sub Form_Load() 

R = Me.OpenArgs 

DoCmd.GoToRecord acDataForm, "Individual Info", acGoTo, R 

End Sub
In the DoCmd.OpenForm, I have added the variable R to the end of the command which is where the variable (or constant) goes to be used as the OpenArg within the form being opened.
Hope this helps!
 
Upvote 0
Vic,

that was it! You got it right on the head....but just to clarify, this OpenArgs property is something that you have to use in an OpenForm or OpenReport , (Open--Whatever)? Just trying to get a better handle on it...

Thanks
Nick
 
Upvote 0
The .OpenArgs would only be available in a Form or Report. Nothing else has a VBA module associated with it. So, in the DoCmd.OpenForm(orReport), the last parameter for those commands is place to put the information you would want to use within the Form or Report.
You can use .OpenArg anywhere within the code behind a Form or Report. You do not have to use it in the OnOpen or OnLoad event, but normally, that is where it would be used.
HTH,
 
Upvote 0

Forum statistics

Threads
1,221,889
Messages
6,162,624
Members
451,778
Latest member
ragananthony7911

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top