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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Built a search function - Can't get it to move to the proper record. 1

Status
Not open for further replies.

DSect

Programmer
Sep 3, 2001
191
US
Hello,

The built in Access search will not work for what I was doing (multi-table form) so I made a search that basically takes a value from a textbox, runs a query and outputs the corresponding invoice number for the text that was searched upon.

I am using LASTNAME to search for an INVOICENUMBER in an order entry situation.

Everything is fine, until I try to get the form to move to the record that is found.

I originally used the GoToRecord method, but I soon realized that it was taking me to the actual RECORD number and not the record who's INVOICENUMBER matches the value of my search results.

Example: A search for the name 'SMITH' reveals that SMITH's INVOICENUMBER is 147.

How can I get my form to move to the corresponding record for SMITH, knowing that his record will be WHERE INVOICENUMBER = 147 ?


Thanks! I hope you understand what I am trying to do.

 
Use the FindRecord method. However, to make this work, you must set focus to the field you searching on. For example,

InvoiceNumber.setfocus
docmd.FindRecord 147
 
Hmm.. I'm getting a goofy run-time error and I bet it's because there is no focus for the find to work in.

Maybe you could clarify something for me:

My form name is "frmEnterAttendees"

The control that needs focus for the find is called "txtInvoiceID".

This code is in a module, so I need to refer to the contols that are not on the current form (correct?).

So I do this:

Dim mainfrm As Form
Set mainfrm = Form_frmEnterAttendees

I'm kinda new to this and I thought I'd be able to set focus by doing:

mainfrm.txtInvoiceID.setfocus

But that doesn't seem to work. Am I screwing up a fundamental VBA principle by doing something wrong in that?


Thanks for your help. In the meantime, I'll try setting focus with a fully-qualified name/path for the control.

Thanks again for the prompt response!
 
Try this:

Dim mainfrm As Form
Set mainfrm = Forms!frmEnterAttendees

mainfrm!txtInvoiceID.setfocus
 
Hey - That was is!

Thanks alot for the help. Being a newbie, some of the little stuff holds me up, ya know..

My search/find works exactly as I need it to - now just have to add some error trapping for Null values and what not..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top