Jumping to a specific record using gotorecord

AlexD

Registered User.
Local time
Today, 08:23
Joined
Sep 20, 2002
Messages
35
Hi,

OK - the problem is this:

Have a main form displaying record details (Company, name, address, etc). Upon clicking a command button, a popup form appears containing filtered records from the main form (just the company name is displayed though). Next to each company name on the popup is a command button. When this button is pressed, I want the main form to display the details of the corresponding company from the popup.

Been trying to do this using a macro (my VB is not too hot) with the gotorecord command. Unfortunately, the offset value only allows you to go to the numeric record number in the recordset.

Is there an expression I can use in the Offset line that will jump to a corresponding record on the main form from my popup?

cheers,

Alex

:confused:
 
Normally the best way to jump to a specified record matching a criteria, you set the form's bookmark property.

I know you say that your VB isn't too good, but it's never too late to learn.

in the onclick event of your command button, use this code

Dim rst as recordset
Set rst=forms![mainformname].recordsetclone
rst.findfirst "[companynamefield]='" & me![txtcompanyname] & "'"
if rst.nomatch=false then
forms![mainformname].bookmark=rst.bookmark
endif

Change the [mainformname] to your main form's name, change [companyfieldname] to the name of the field in your table that stores the company name, change [txtcompanyname] to the name of the textbox on the popup form that displays the company name.

Basically what this code does is creates an exact replica (clone) of the main forms records. Then it looks through all of those records until it finds the company displayed on the popup form. If it finds the company, it sets the bookmark property of the main form to the clone's bookmark. In effect moving to the appropriate record.
 
Cheers Charity,

That worked a treat. I should learn VB rather than messing around with macros...:)

Thanks again.

Alex
 

Users who are viewing this thread

Back
Top Bottom