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

OnGotFocus Issue

Status
Not open for further replies.

hockeyman9474

IS-IT--Management
Oct 11, 2007
17
US
OK. I think I'm going crazy. I have been spending all day trying to figure this out, but all the whitepapers and all the books in the world aren't helping. Here is how my db is set up:

I have a form with textboxes linked to those on a table. It is a client table. To have this table linked with another, I have an account number cloumn preset with the numbers 001-100. On my form there is a TB called Account Number which obviously populates with 001, 002, 003, etc. All I need to do is replace what is in there(and on the table record) with a persons last name and the number. So instead of 001 it will appear smith001 for exmaple. I am using OnGotFocus in the properties window on the account number textbox to concatenate so it looks like =[Last Name] & [Account Number]. When I tab to the Acct# TB it won't do what I asked it to do. What am I missing?

Adam
 
Are you getting an error message?

Do you have the Control Source of the text box equal to something?

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
no error message just keep what was originally there, there. Which in this case for the first record was 001. By control source you mean.....


I went to the properties of the textbox/event tab/ ongotfocus and created in expression builder.

=[Last Name]&[Account Number]

All textboxes were added as existing fields from the table. The account number tb brings over what is in the table field in this case 001 and last name text box shows what is in the last name field on the table which right now is nothing. But I am askinf the account number TB to concat. What is in the two textboxes and it's not.
 
The Control Source is the property of the text box that determines where the data comes from or goes to. If your text box is bound to a field in the table then your Control Source should be the same as the field name in the table.

If you are trying to change the value of the text box when you click on it, then you should put this in vba code in the On Focus event procedure.

[Account Number]=[Last Name]&[Account Number]

When you leave the record it will be saved. If you are trying to change all the records to show the Last Name & Account Number then you should do this with an update query and do it on one swoop. I say that because if the field is bound and you click on it, then it will be Smith001.
The next time you click on it, then it will be SmithSmith001 and so on.

I hope I am understanding you correctly.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
You are 100% correct. Only when I create this in the expression builder it changes it to =[Account Number]=[Last Name]&[Account Number], and it doesn't concatenate it. In fact it just leaves there what is originally there. In this case it's the number already assigned to it 001, 002, so on and so forth. But you raise an excellent point. What if I goto a record already completed and tab through it. Once the the TB gets the focus it'll take Smith001 and concatenate itself making the new value SmithSmith001. The next time will be SmithSmithSmith001. What if I wanted it to concatenate only the first time, then I have to write some code right? I know coding but I was making an attempt at a DB w/o writing in code.
 
Lonnie,

What about this? What if I had a column in my table called ID and I made ID=001, 002,....

Then when the record displays the first TB to get the focus was Last Name. When Last Name gets the focus which is immediately, I let Account Number=Last Name(from form)&ID(from table). That way the Account number never gets over written.
 
Can I back up and ask you the purpose of this or what you are actually trying to accomplish? Thanks.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top