Command Button to populate a field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a trick to populate a field instantly when you click a command
button? I have a button that when I click it the following VB code executes:
me.address="My House". It does update the field, but not right away. I have
to leave the record and come back to it to see the change.
Later on I want to replace "my house" with the value of a field on a
different form:
me.address= Forms!Clients!Address
Is there a way to do this without having the form open? Or should I just
base it on the table?
Thanks a lot in advance for your help.
 
Ok, I found the first part, I was using the field value and not the control
to populate the field. So instead of me.address I used me.location, which is
the name of the control. Still the second part I want to solve, I want to
populate the address based on another form without having the other form open.
 
check your Access help file for info on the DLookup function. You can use
this to lookup a value in another table.

HTH
 
Is there a trick to populate a field instantly when you click a command
button? I have a button that when I click it the following VB code executes:
me.address="My House". It does update the field, but not right away. I have
to leave the record and come back to it to see the change.
Later on I want to replace "my house" with the value of a field on a
different form:
me.address= Forms!Clients!Address
Is there a way to do this without having the form open? Or should I just
base it on the table?
Thanks a lot in advance for your help.

Data is not stored in forms; it's stored in tables. And you should very rarely
or never need to store the same address in two different tables.

Just what are you trying to accomplish? What's the Recordsource of this form?

John W. Vinson [MVP]
 
Ok, I found the first part, I was using the field value and not
the control to populate the field. So instead of me.address I used
me.location, which is the name of the control. Still the second
part I want to solve, I want to populate the address based on
another form without having the other form open.
If the form is not open, then it contains no address, so your method
will fail. You need to retrieve the address from the table or query,
based on a parameter on your open form. DLookup() is good for that,
see the help for the way to use it.
 
Thanks for the responses, DLookup works great for what I want. The reason I
have another address in another table is because sometimes I have 2 different
addresses for each client. Sometimes more. Each client has many events and
those events might not be in the clients premises. That is why I wanted a
button, when the address is different, I won't use that button, but if the
address is the same, then all I have to do is click the Address Button.
Thanks John and Bob and Beetle.
 
Back
Top