Macro which fills fields from other fields

Dinictus

Board Regular
Joined
Mar 19, 2002
Messages
162
Hi,

I hava a small dbase in which we store address information. Now you have a visit address, a mailing address and billing adress.

I want to use some buttons which trigger macro's to fill in these "Secondairy" addresses from the visit adress.

So a buttun that says: copy billing address from visit address. and then the street, Number, PO box en city will be copied from the visit address to the billing address.

It's probably possible through a macro but I'm having a hard time coming up with the syntax. Or it there an easier way.

I hope you guys can help me out. THANKS!!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Okay,

Now I've done some thinking and I found out that I will need to build a query to do this. Am I correct? Ist here anyone who can help me set this one up?

How can I fill the to-be-filled with the contents of the query?

Hope you can help. Thnks.
 
Upvote 0
Hi, in answer to this question :

Now I've done some thinking and I found out that I will need to build a query to do this. Am I correct? Ist here anyone who can help me set this one up?

Yes you can do this with a query, as follows :

Create a new query -> design view -> ok -> select the table with the addresses -> add -> close. Click Query -> Update Query.

Add the secondary address fields into the field part of the query <- these are the fields that will be updated. In the "Update To" section, under the relevant secondary address enter the variable name that you wish to use to update the secondary address inside square brackets e.g. if the first secondary address to updated is "billing_address_1" then the update to part should read [first address 1] {but with your variable name and you have to use the square brackets}.

You can update multiple fields at the same time - so you can do all of the secondary addresses in one query.

To stop the query writing over any values that you might have entered already, enter "Is Null" (without the quotes) into the criteria section for every column.

Save the query.

In answer to your first question :

I want to use some buttons which trigger macro's to fill in these "Secondairy" addresses from the visit adress

Create a new macro, the first line should read "Open Query" and the query will be query you created above. The second line in the macro should be "Stop Macro". Save the macro.

You can attach the macro to your button (right click your button on the form -> Properties -> Event -> On Click -> select your macro -> Close. Save.

We can introduce some other features (to stop the pop up box) into your macro once this is working.

HTH, Andrew. :)

P.S. there is a Microsoft article on update queries here and an article on creating a macro here..
 
Upvote 0
Hi Andrew,

Thanks a lot for your solutions. I'm gonnen try it out tonight but when reading it, i'm sure I can make this work!

Thanks a whole lot man!!
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,248
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top