Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.GoToRecord

Status
Not open for further replies.

illini

Technical User
Aug 2, 2002
89
FR
I'm experiencing a problem with DoCmd.GoToRecord.

I have a form with a listbox of records. I want to enable the user to double-click on a record and for another form to open to it.

The following code uses an Contact_ID to look for the record. However, it's possible to have the Contact_ID value greater than the total number of records (due to deleted records). Therefore, I receive an error when I try to pull a record with a Contact_ID of '402' when there are only 399 records.

Any help would be appreciated.

Private Sub LB_Contacts_DblClick(Cancel As Integer)

x = LB_Contacts.Column(6)[/color] ' x assigned Contact_ID
DoCmd.OpenForm "Frm_Contacts", acNormal
DoCmd.GoToRecord acDataForm, "Frm_Contacts", acGoTo = x

End Sub
-illini
 
i presume contact_id comes from a table. just set the recordsource of a combobox to the table with this one field using a query. and then set limit to list to yes.
"What a wonderfull world" - Louis armstrong
 
The Contact_ID comes from a table.

My form currently has a Listbox with a recordset which is based on a query of this table. The user is limited to the list.

The list can be sorted in a variety of ways. So, in order to enable the correct record to be pulled when the listbox is double-clicked, 'x' is set to equal the Contact_ID.

However, instead of the DoCmd.GoToRecord going to the record with the correct Contact_ID (e.g. '403'), it selects the 403rd record in the table. If the table only has 399 records, I receive an error. -illini
 
ah now i understand, sorry for being slow.

But i think you wil need to use find or seek
with gotorecord you will never get there.
"What a wonderfull world" - Louis armstrong
 
Any ideas on how to use the 'Find' or 'Seek' to obtain the correct record? -illini
 
uhm, no

personnaly i never use it, try it in a new thread, or try the help file i believe this is descibed there "What a wonderfull world" - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top