Hyperlink to a specific record in another form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create a hyperlink that will open up a specific record in
another form instead of always opening to the first record. Does anyone know
how to do that? Thanks
 
Not sure how this would apply to a hyperlink, but you can use the Bookmark
property to identify & bring up a particular record.

Me.RecordsetClone.FindFirst "[CustomerID] = " & <CustomerIDOfDesiredRecord>
Me.Bookmark = Me.RecordsetClone.Bookmark

I use this to navigate to a specific record selected in a combo box on the
form itself, thus the "Me" refers to the same form. It finds the first record
matching the desired CustomerID (FindFirst), then goes to that record
(Me.Bookmark = ...).

You would just have to pass the desired value from your hyperlink to the
form that is to be opened (perhaps as a public variable) and put the above
code in the form's open event.

Optionally, you could filter the form as it is opened to just the record you
want by referring to the value of the hyperlink in the criteria line of the
form's RecordSource query.
 
Bookmarks are not presisent and in any case, would not transfer from one form
to another.
Hyperlinks do not apply in this situation. Hyperlinks take you to a
specific document or file, not to a record in a table.
The most common way to open a form to a specific record from another form is
to use either the Where argument or the OpenArgs argument of the OpenForm
method. My preference is the OpenArgs argument.
Assume FormA opens FormB and you want FormB to open to a customer selected
in FormA.
In FormA:

Docmd.OpenForm "FormB", , , , , , Me.txtCustID

In the Load Event of FormB:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "[CustID] = " & Me.OpenArgs
If .NoMatch Then
Msg Box "Customer " & Me. OpenArgs & " Not Found"
Else
Me.Bookmark = .BookMark
End If
End With
End If
--
Dave Hargis, Microsoft Access MVP


Brian said:
Not sure how this would apply to a hyperlink, but you can use the Bookmark
property to identify & bring up a particular record.

Me.RecordsetClone.FindFirst "[CustomerID] = " & <CustomerIDOfDesiredRecord>
Me.Bookmark = Me.RecordsetClone.Bookmark

I use this to navigate to a specific record selected in a combo box on the
form itself, thus the "Me" refers to the same form. It finds the first record
matching the desired CustomerID (FindFirst), then goes to that record
(Me.Bookmark = ...).

You would just have to pass the desired value from your hyperlink to the
form that is to be opened (perhaps as a public variable) and put the above
code in the form's open event.

Optionally, you could filter the form as it is opened to just the record you
want by referring to the value of the hyperlink in the criteria line of the
form's RecordSource query.

amie said:
I am trying to create a hyperlink that will open up a specific record in
another form instead of always opening to the first record. Does anyone know
how to do that? Thanks
 
Brian-
Thanks. What you are describing seems to be what I want to do, but it went
completely over my head. Could you tell me, or refer me to somewhere I can
figure out how to do this step by step? I just taught myself the basics of
access over the past few weeks, so virtually all of the writing codes stuff
is way over my head.
Thanks so much.
--
Amie


Klatuu said:
Bookmarks are not presisent and in any case, would not transfer from one form
to another.
Hyperlinks do not apply in this situation. Hyperlinks take you to a
specific document or file, not to a record in a table.
The most common way to open a form to a specific record from another form is
to use either the Where argument or the OpenArgs argument of the OpenForm
method. My preference is the OpenArgs argument.
Assume FormA opens FormB and you want FormB to open to a customer selected
in FormA.
In FormA:

Docmd.OpenForm "FormB", , , , , , Me.txtCustID

In the Load Event of FormB:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "[CustID] = " & Me.OpenArgs
If .NoMatch Then
Msg Box "Customer " & Me. OpenArgs & " Not Found"
Else
Me.Bookmark = .BookMark
End If
End With
End If
--
Dave Hargis, Microsoft Access MVP


Brian said:
Not sure how this would apply to a hyperlink, but you can use the Bookmark
property to identify & bring up a particular record.

Me.RecordsetClone.FindFirst "[CustomerID] = " & <CustomerIDOfDesiredRecord>
Me.Bookmark = Me.RecordsetClone.Bookmark

I use this to navigate to a specific record selected in a combo box on the
form itself, thus the "Me" refers to the same form. It finds the first record
matching the desired CustomerID (FindFirst), then goes to that record
(Me.Bookmark = ...).

You would just have to pass the desired value from your hyperlink to the
form that is to be opened (perhaps as a public variable) and put the above
code in the form's open event.

Optionally, you could filter the form as it is opened to just the record you
want by referring to the value of the hyperlink in the criteria line of the
form's RecordSource query.

amie said:
I am trying to create a hyperlink that will open up a specific record in
another form instead of always opening to the first record. Does anyone know
how to do that? Thanks
 
You said you want to open one form from another and when the form is opened,
it opens at a specific record, not necessarily at the first record.
What I described previously is how it is done. Perhaps you need a bit more
detail.
For starters, Access assigns meaningless names to objects as you create
them. It is best to always change those names to something meaningful. It
makes your work much easier. You don't have to try to remember what Text1 or
Combo316 or Command4 are. Names like txtEmployeeID, cboJobCode, or cmdCancel
give you a lot more information. For example, txtEmployeeID tells me that it
is a text box because it starts with txt and it will contain the Employee
Identification number.

When you open a form that is not a Data Entry form (A Data Entry form only
allows new records to be created and you can't display or edit existing
records), the normal situation is for the form to display the first record in
the form's recordset. The form's recordset is identified by the Record
Source property. It can be either a table or a query. The sort order can be
determined by the query or by the form, but in either case the first record
will be the first in the sort order specifed. If no sort order is specified,
it will be presented in the order of the primary key.

It is possible to open a form with a new record displayed (all controls will
appear blank unless a default value has been specified), or a specified
record. There are a couple of ways to specify the record you want to show.
One is to use the OpenArgs argument of the OpenForm method. That is the
technique I described previously. You can read detail on both in VBA Help.
The OpenForm method opens a form. There are various things you can specify
when the form opens. One of them is called the OpenArgs argument (An
argument is a value you pass to a method, a function, or a sub that gives it
information so it can do what you want it to.) The OpenArgs argument is a
string value. It can be any string value that will be meaningful to your
application.

When the form opens, it has a property named OpenArgs. It is addressed as
Me.OpenArgs (the Me. being the shorthand for the active form). If no value
was passed from the object that opened the form, OpenArgs will be Null;
otherwise, it will be the value passed. What you use the OpenArgs property
for is up to you. It can be used for different actions.
One of those actions is to position the form's recordset so that a specific
record is displayed. The technique is to check to see whether OpenArgs is
Null or not. In this case, if it is Null, we take no action; otherwise, we
assume the value received from the opening object is the value of primary key
for a customer record, so we check to make sure the value exists in the
recordset and if it is, make it the current record.

Let's break it down line by line:

'Check to see if OpenArgs has a value. If it does not, do nothing (none of
the following code to the last End If is executed)
If Not IsNull(Me.OpenArgs) Then
'Use a copy of the form's recordset (Everything that starts with . between
the With and the End With is a property or method of Me.RecordsetClone
With Me.RecordsetClone
'Find the first record where the field CustID is equal to the value received
from the opening object.
.FindFirst "[CustID] = " & Me.OpenArgs
'If we don't find a matching record in the table
If .NoMatch Then
'Display a message that we did not find the record
Msg Box "Customer " & Me. OpenArgs & " Not Found"
Else
'Make the record found the current record
Me.Bookmark = .BookMark
End If
End With
End If

The BookMark property is a unique indentifier for every record in a
recordset. The form recordsetclone will have different bookmark from that of
the form recordset. A bookmark is only good for the current session. If you
close and reopen the form, the bookmarks will be different.

Hope this helps.

--
Dave Hargis, Microsoft Access MVP


amie said:
Brian-
Thanks. What you are describing seems to be what I want to do, but it went
completely over my head. Could you tell me, or refer me to somewhere I can
figure out how to do this step by step? I just taught myself the basics of
access over the past few weeks, so virtually all of the writing codes stuff
is way over my head.
Thanks so much.
--
Amie


Klatuu said:
Bookmarks are not presisent and in any case, would not transfer from one form
to another.
Hyperlinks do not apply in this situation. Hyperlinks take you to a
specific document or file, not to a record in a table.
The most common way to open a form to a specific record from another form is
to use either the Where argument or the OpenArgs argument of the OpenForm
method. My preference is the OpenArgs argument.
Assume FormA opens FormB and you want FormB to open to a customer selected
in FormA.
In FormA:

Docmd.OpenForm "FormB", , , , , , Me.txtCustID

In the Load Event of FormB:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "[CustID] = " & Me.OpenArgs
If .NoMatch Then
Msg Box "Customer " & Me. OpenArgs & " Not Found"
Else
Me.Bookmark = .BookMark
End If
End With
End If
--
Dave Hargis, Microsoft Access MVP


Brian said:
Not sure how this would apply to a hyperlink, but you can use the Bookmark
property to identify & bring up a particular record.

Me.RecordsetClone.FindFirst "[CustomerID] = " & <CustomerIDOfDesiredRecord>
Me.Bookmark = Me.RecordsetClone.Bookmark

I use this to navigate to a specific record selected in a combo box on the
form itself, thus the "Me" refers to the same form. It finds the first record
matching the desired CustomerID (FindFirst), then goes to that record
(Me.Bookmark = ...).

You would just have to pass the desired value from your hyperlink to the
form that is to be opened (perhaps as a public variable) and put the above
code in the form's open event.

Optionally, you could filter the form as it is opened to just the record you
want by referring to the value of the hyperlink in the criteria line of the
form's RecordSource query.

:

I am trying to create a hyperlink that will open up a specific record in
another form instead of always opening to the first record. Does anyone know
how to do that? Thanks
 

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

Back
Top