GoToRecord Action

  • Thread starter Thread starter Ginger
  • Start date Start date
G

Ginger

I have a form that shows product in a grid style, based on
selections. When a record is selected, and I click on the
Edit button, that opens up the Edit form. But it is always
at the first record, not the record I want to edit.
I understand there is the "GoToRecord" Action that is
supposed to accomplish this. I'm not quite understanding
this action.
Do I need to set the value for the Offset argument or what.
Could someone please assist?

Thank you in advance.

Ginger
 
I have a form that shows product in a grid style, based on
selections. When a record is selected, and I click on the
Edit button, that opens up the Edit form. But it is always
at the first record, not the record I want to edit.
I understand there is the "GoToRecord" Action that is
supposed to accomplish this. I'm not quite understanding
this action.
Do I need to set the value for the Offset argument or what.
Could someone please assist?

You can limit what's displayed in the Edit form to the record selected by
passing a record identifier as an argument in the "OpenForm" method. If your
record has a "ProductID" field, you can use this as the record identifier. If
your Edit button was created using the control wizard, you can simply set the
value of "stLinkCriteria" in the following manner:

The following line is generated in the command button by the control wizard:

Dim stLinkCriteria As String

After that line, enter whichever of the following lines is appropriate for your
application:

'If the ProductID is a number
stLinkCriteria = "ProductID=" & Me!ProductID

.... Or ...

'If the ProductID is a string
stLinkCriteria = "ProductID=""" & Me!ProductID & """"

The following line, which is also generated by the control wizard, will now open
the form showing only the record with the ProductID matching that of the record
you want to edit by passing the new value of "stLinkCriteria" as an argument to
the "OpenForm" method:

DoCmd.OpenForm stDocName, , , stLinkCriteria

Make sure that you replace "ProductID" with the name of the product number field
in your project.
 
Ginger,

No, the GoToRecord action is not applicable to your task here. I
assume your macro that is on the Edit button's OnClick event property
is using an OpenForm action. If so, you should use the Where
Condition argument of the OpenForm action. How do you uniquely
identify your records? Is there an ID field of some sort, which will
of course be part of the recordsource of both forms? If so, refer to
this field in the Where Condition argument using syntax such as...
="[YourID]=" & [YourID]

- Steve Schapel, Microsoft Access MVP
 
Thank you Bruce. I'll be putting that in now and see how it
works.
Yes, the button was created with the wizard and the ID
field is numeric (autonumber).
Once again, thank you.

Ginger

-----Original Message-----

You can limit what's displayed in the Edit form to the record selected by
passing a record identifier as an argument in the "OpenForm" method. If your
record has a "ProductID" field, you can use this as the record identifier. If
your Edit button was created using the control wizard, you can simply set the
value of "stLinkCriteria" in the following manner:

The following line is generated in the command button by the control wizard:

Dim stLinkCriteria As String

After that line, enter whichever of the following lines is appropriate for your
application:

'If the ProductID is a number
stLinkCriteria = "ProductID=" & Me!ProductID

.... Or ...

'If the ProductID is a string
stLinkCriteria = "ProductID=""" & Me!ProductID & """"

The following line, which is also generated by the control wizard, will now open
the form showing only the record with the ProductID matching that of the record
you want to edit by passing the new value of
"stLinkCriteria" as an argument to
 
I guess that does not work, as I get "variable not defined"
So what is the correct way to reference the record in the
subform?

Ginger

-----Original Message-----

You can limit what's displayed in the Edit form to the record selected by
passing a record identifier as an argument in the "OpenForm" method. If your
record has a "ProductID" field, you can use this as the record identifier. If
your Edit button was created using the control wizard, you can simply set the
value of "stLinkCriteria" in the following manner:

The following line is generated in the command button by the control wizard:

Dim stLinkCriteria As String

After that line, enter whichever of the following lines is appropriate for your
application:

'If the ProductID is a number
stLinkCriteria = "ProductID=" & Me!ProductID

.... Or ...

'If the ProductID is a string
stLinkCriteria = "ProductID=""" & Me!ProductID & """"

The following line, which is also generated by the control wizard, will now open
the form showing only the record with the ProductID matching that of the record
you want to edit by passing the new value of
"stLinkCriteria" as an argument to
 
Now I get an error message:

Microsoft Access can?t find the form ?frmSelectAllByMake?
referred to in a macro expression or Visual Basic code.
*The form you referenced may be closed or may not exist in
this database
*Microsoft Access may have encountered a compile error in a
Visual Basic module for the form

Is this because I close it before opening the edit form?

Thanks,
Ginger
-----Original Message-----
Ginger,

No, the GoToRecord action is not applicable to your task here. I
assume your macro that is on the Edit button's OnClick event property
is using an OpenForm action. If so, you should use the Where
Condition argument of the OpenForm action. How do you uniquely
identify your records? Is there an ID field of some sort, which will
of course be part of the recordsource of both forms? If so, refer to
this field in the Where Condition argument using syntax such as...
="[YourID]=" & [YourID]

- Steve Schapel, Microsoft Access MVP


I have a form that shows product in a grid style, based on
selections. When a record is selected, and I click on the
Edit button, that opens up the Edit form. But it is always
at the first record, not the record I want to edit.
I understand there is the "GoToRecord" Action that is
supposed to accomplish this. I'm not quite understanding
this action.
Do I need to set the value for the Offset argument or what.
Could someone please assist?

Thank you in advance.

Ginger

.
 
Ginger,

stLinkCriteria = "ID=" & Me.subfrm_Product_by_Make.Form!ID
or
stLinkCriteria = "ID=" & Me![subfrm Product by Make].Form!ID

- Steve Schapel, Microsoft Access MVP
 
OK, I see from elsewhere that I got off on the wrong track here...
When you mentioned the GoToRecord action I took it that you were using
a macro.

- Steve Schapel, Microsoft Access MVP


Ginger,

No, the GoToRecord action is not applicable to your task here. I
assume your macro that is on the Edit button's OnClick event property
is using an OpenForm action. If so, you should use the Where
Condition argument of the OpenForm action. How do you uniquely
identify your records? Is there an ID field of some sort, which will
of course be part of the recordsource of both forms? If so, refer to
this field in the Where Condition argument using syntax such as...
="[YourID]=" & [YourID]

- Steve Schapel, Microsoft Access MVP


I have a form that shows product in a grid style, based on
selections. When a record is selected, and I click on the
Edit button, that opens up the Edit form. But it is always
at the first record, not the record I want to edit.
I understand there is the "GoToRecord" Action that is
supposed to accomplish this. I'm not quite understanding
this action.
Do I need to set the value for the Offset argument or what.
Could someone please assist?

Thank you in advance.

Ginger
 
Steve,
I still need assistance. I can't get either button to work,
not the one with a macro and not the one built by the
wizard. I posted an error message I get. Can you still help
please? I must be doing something wrong.

Ginger
-----Original Message-----
OK, I see from elsewhere that I got off on the wrong track here...
When you mentioned the GoToRecord action I took it that you were using
a macro.

- Steve Schapel, Microsoft Access MVP


Ginger,

No, the GoToRecord action is not applicable to your task here. I
assume your macro that is on the Edit button's OnClick event property
is using an OpenForm action. If so, you should use the Where
Condition argument of the OpenForm action. How do you uniquely
identify your records? Is there an ID field of some sort, which will
of course be part of the recordsource of both forms? If so, refer to
this field in the Where Condition argument using syntax such as...
="[YourID]=" & [YourID]

- Steve Schapel, Microsoft Access MVP


I have a form that shows product in a grid style, based on
selections. When a record is selected, and I click on the
Edit button, that opens up the Edit form. But it is always
at the first record, not the record I want to edit.
I understand there is the "GoToRecord" Action that is
supposed to accomplish this. I'm not quite understanding
this action.
Do I need to set the value for the Offset argument or what.
Could someone please assist?

Thank you in advance.

Ginger

.
 
Thanks Steve,
Does this mean I need to change the name of my form so
there are no spaces?

Ginger
-----Original Message-----
Ginger,

stLinkCriteria = "ID=" & Me.subfrm_Product_by_Make.Form!ID
or
stLinkCriteria = "ID=" & Me![subfrm Product by Make].Form!ID

- Steve Schapel, Microsoft Access MVP


I guess that does not work, as I get "variable not defined"
So what is the correct way to reference the record in the
subform?

Ginger

.
 
Bruce,
You are correct. That is what I am trying to do. I'll
change it to the name of the control and give it one more try.
If it doesn't work, I'll get back with you.

Thank you so very much.

Ginger

-----Original Message-----
Bruce, I just have one more quick question on this. The
form contains a subform and that is the one that contains
the records. So would it be correct to have the reference
like this:

Dim stLinkCriteria As String
stLinkCriteria = "ID=" & subfrm Product by Make!ID

Just as Steve has suggested further into this thread:

stLinkCriteria = "ID=" & Me.[subfrm Product by Make].Form.!ID

You need to replace "subfrm Product by Make" with the name of the subform
*control* on your main form (not the subform's name, although both may share the
same name) and the actual name of the "ID" field, if it differs from that shown
in the example. I am presuming that the intended action is to click in the
pertinent record in the subform and then click on the button on the main form,
is that correct? If that is not the case or if it still doesn't work properly,
let us know as you may need to provide more information in order for someone to
understand what is not working properly.

--
Bruce M. Thompson, Microsoft Access MVP
(e-mail address removed) (See the Access FAQ at http://www.mvps.org/access)within the newsgroups so that all might benefit.<<


.
 
Bruce,

That worked! Thank you ever so much.

Ginger

-----Original Message-----
Bruce, I just have one more quick question on this. The
form contains a subform and that is the one that contains
the records. So would it be correct to have the reference
like this:

Dim stLinkCriteria As String
stLinkCriteria = "ID=" & subfrm Product by Make!ID

Just as Steve has suggested further into this thread:

stLinkCriteria = "ID=" & Me.[subfrm Product by Make].Form.!ID

You need to replace "subfrm Product by Make" with the name of the subform
*control* on your main form (not the subform's name, although both may share the
same name) and the actual name of the "ID" field, if it differs from that shown
in the example. I am presuming that the intended action is to click in the
pertinent record in the subform and then click on the button on the main form,
is that correct? If that is not the case or if it still doesn't work properly,
let us know as you may need to provide more information in order for someone to
understand what is not working properly.

--
Bruce M. Thompson, Microsoft Access MVP
(e-mail address removed) (See the Access FAQ at http://www.mvps.org/access)within the newsgroups so that all might benefit.<<


.
 
Well, it worked fine for the first form, but when I copied
it to the 2nd form, it does not like the line:
DoCmd.openform....

Do you think I should name all the subforms the same name,
and have one public code that goes to the edit form? would
that work?

Ginger

-----Original Message-----
Bruce, I just have one more quick question on this. The
form contains a subform and that is the one that contains
the records. So would it be correct to have the reference
like this:

Dim stLinkCriteria As String
stLinkCriteria = "ID=" & subfrm Product by Make!ID

Just as Steve has suggested further into this thread:

stLinkCriteria = "ID=" & Me.[subfrm Product by Make].Form.!ID

You need to replace "subfrm Product by Make" with the name of the subform
*control* on your main form (not the subform's name, although both may share the
same name) and the actual name of the "ID" field, if it differs from that shown
in the example. I am presuming that the intended action is to click in the
pertinent record in the subform and then click on the button on the main form,
is that correct? If that is not the case or if it still doesn't work properly,
let us know as you may need to provide more information in order for someone to
understand what is not working properly.

--
Bruce M. Thompson, Microsoft Access MVP
(e-mail address removed) (See the Access FAQ at http://www.mvps.org/access)within the newsgroups so that all might benefit.<<


.
 
Well, it worked fine for the first form, but when I copied
it to the 2nd form, it does not like the line:
DoCmd.openform....

Are you saying that you copied the code to another *main* form with a subform?
What do you mean "it does not like the line ..."? Was there an error message
and, if so, what was it?
Do you think I should name all the subforms the same name,
and have one public code that goes to the edit form? would
that work?

You can't name all the *subforms* the same, but you can, on multiple main forms,
name a subform *control* the same. You *could* write a function to call the edit
form, but there really isn't so much code involved that the effort would be
warranted.
 
Back
Top