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

Locate 2

Status
Not open for further replies.

Lewy

Technical User
Nov 16, 2001
170
GB
Hi everyone,

I know this should be simple but I am going around in circles trying to get a pushbuuton to bring up a form which asks for LastName and FirstName. On pressing OK I want to locate the record in a Customer table which matches the LastName and FirstName entered. The table contains amongst others a LastName and FirstName field.

Any help as always much appreciated.

Thanks,

Lewy
 
Lewy,

This should be fairly simple to do. Set up a locate form with a first name and last name field and a locate button. When the button is pushed you should add code something like:

var
tc tcursor
f form
endvar

tc.open("customer database")
if tc.locate("lastname", lastnamefield, "firstname", firstnamefield) then
f.attach("Customer Form")
f.customertable.movetoRecord(tc)
else
msgStop("Error","Couldn not locate cursomer.")

endif
tc.close()


hope this helps.
Perrin
 
Kliot,

Many thanks for your reply. I perhaps didn't explain the problem very clearly. I want to be able to push a button on the main Customer dataentry form which brings up another form in which to enter the first & Last name I am searching for. On closing this search form I wish to return to the correct record on the Customer data entry form, if that makes sense.

Thanks,

Lewy
 
Lewy,

Kilot's post seems to be the solution.

Presumably the Locate_form would be opened from a button on the Customer_form
Var
f form
Endvar
f.open("Locate_form")

The first & Last name would be unbound fields on the Locate_form.

You may just want to put Kilot's code above behind a Close Buttton on the Locate_form if such is your preference.

Regards

Bystander
 
Bystander,

Thanks for adding to the post, I assumed Lewy understood how to open the locate form with a button. I should have included adding close() after f.customertable.movetoRecord(tc) to close the lookup form after a successful search.

Lewy, you may also want to open the form as a dialogbox with a wait command
f.openAsDialog("Locate_Form")
f.wait()
f.close()

and on the Locate_Form instead of using close() use FormReturn("Ok")

This will freeze the main form while the user is working on the lookup form.
 
Thanks for your help,

BUT....

I have set up a button on the main Customer data entry form which opens a search form, I didn't have any problems there. When I perform a search I keep getting the error message "Couldn't locate customer". I have tried every which way to get this code to work to no avail, I guess it is something so obvious I cannot see it.

Help.....

Thanks.

Lewy
 
Lewy,

Sounds like you're missing something simple, can you post your code and the exact field names of the table?

Perrin
 
Kliot,

Many thanks, like I said it's going to be something simple, so here is all the information:
The main customer table (Cust1) has the following structure:

Customer_No N* Key field
Date D
Title A6 ie Mr/Mrs etc..
FirstName A12
LastName A20
No and Street A40

etc...

Code on the button on the data entry form (the name of the form is Cs2)is:

var
f form
endvar

f.openAsDialog("persrch")
f.wait()
f.close()

This opens another form called "Persrch", whereby the field for inputting the customers surname is called(from the properties) LastNameFld and likewise the field for inputting the firstname is FirstNameFld.

The code on this forms search button is:

var
tc tcursor
f form
endvar

tc.open("Cust1")
if tc.locate("LastName", LastNameFld, "FirstName", FirstNameFld) then
f.attach("Cs2")
f.Cs2.movetoRecord(tc)
FormReturn("OK")
else
msgStop("Error","Couldn not locate customer.")

endif

Hope this helps,

Thanks,

Lewy
 
Lewy,

Everything looks good to me, I even created a table and form with the same structure as you gave and it works perfect. One thing that may be causing the problem is case sensitivity, the locate is by default case sensitive. Try adding ignoreCaseInLocate(true) before the locate method.

Let me know if this is the problem
Perrin
 
Kliot,

Didn't make any difference. I have obviously tried altering the code to try and get this to work and one error message came up was that the table wasn't open!! Could this be where the problem is? Now I am really getting frustrated......

Thanks,

Lewy
 
Have you tried adding:

if not tc.open("Cust1") ; could you need an alias here?
then errorShow()
endif


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Langley,

Yup, just tried that, still get the message 'couldn't find record'. I am just about to give up. I still think I am doing something fundamentally wrong but Im'e b****red if I know what! Could someone tell me step by step perhaps starting with a new loctate form what I should be doing.

Presently the locate form is not attached to any table and I have two fields on the form, which I have called (through properties) LastNameFld & FirstNameFld, the values entered into these two fields are what I wish to locate in the main cust1 table, this is shown on the screen as a form named Cs2.

Hoping this further information may help?

Lewy
 
Try adding this right quick:

if NOT tc.locate("LastName", LastNameFld, "FirstName", FirstNameFld) then errorShow()
endif

instead of your existing locate code and see what the >> error message indicates.


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Langley,

Error messages are as follows:

Messages given by pressing the>> button,
Field "FirstName" is not a field in Cust1 table
Field '0' is not a field in Cust1 table
Field 'FirstName' is not a field in cust1 table
Field '0' is not a field in Cust1 table
Field 'LastName' is not a field is Cust1 table
Field '0' is not a field in Cust1 table
Field 'LastName' is not a field is Cust1 table

I presume that I have the field names incorrect! But I have taken the names from Info-structure.

Lewy
 
First, are there spaces or underscore in the field names?

Next, I want you check the values of the variables. Place this before the locate statement:

view(lastNameFld+", "+firstNameFld)

to see if your variables are being assigned.



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Have just checked the table structure and the fields are Last Name & First Name with a space between the words. With the last line of code the view box came up with both names I had entered into the fields.

Lewy
 
Then you need to have those spaces in your locate statement.

if tc.locate("Last Name", LastNameFld, "First Name", FirstNameFld) then
f.attach("Cs2")
f.Cs2.movetoRecord(tc)
FormReturn("OK")
else
msgStop("Error","Couldn not locate customer.")

endif


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
THought we had cracked it, wrong!!

If I just fill the lastname box, I get the error message, couldn't find customer. If I fill in a last name and a first name I get the error message, you have tried to access a document that is not open.

Below is the code placed on the button

var
tc tcursor
f form
endvar

tc.open("Cust1")
if not tc.open("Cust1") ; could you need an alias here?
then errorShow()
endif

ignoreCaseInLocate(true)
if tc.locate("Last Name", LastNameFld, "First Name", FirstNameFld) then
f.attach("Cs2")
f.Cs2.movetoRecord(tc)
FormReturn("OK")
else
msgStop("Error","Couldn not locate customer.")

endif

I shall soon end up sitting blubbering in the corner!

Thanks for all your help so far.
Lewy
 
I can tell you it won't work if you only fill in a last name. So that part of the code is actually working the way it should, since both variables have to be assigned (even though that's probably not the result you wanted - we'll fix it in a minute).

The good news is that the locate worked, but the document (the form) failed to open. I was focusing on the locate code and ignoring the greater problem. You are trying control events on one form from another. Which is problematical at best. I use setRange and an environment variable to accomplish this. Others may have different methods - Footpad would be a good choice to advise you on alternate methods.

Give me a few minutes and I'll post an example of how I do this.





Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Okey dokey!!

And there was me thinking it was simple! I had managed to program a button using 'menuAction(MenuRecordLocateValue)'or CtrlZ that brought up a dialog box , enter the Last Name and Bang! it went to the first instance of that Last Name. I was trying to modify the search button to take me direct to a record by inputting first & Last Name instead of having to use 'menuAction(MenuRecordLocateNext)' or CtrlA.

Thanks once again,

Lewy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top