Auto Fill Field

scottwyman

New member
Local time
Today, 12:18
Joined
Jul 27, 2009
Messages
4
Greetings All,

I'm not new to Access, but i am new to VBA. I have a database with multiple tables and forms used to process customer transactions. What I'm trying to do is have Access open a new blank invoice form and automatically fill in the Customer ID based on the current form. Does this make sense? Any help would be greatly appreciated.

Scott
 
You could pass the customerid as an OpenArgs paramater to the form . Use the forn's On Load event to populate the control witht he value in the Me.OpenArgs
 
Coach,

I try not to be slow, but some times I can't help it. Can you break that down for me a little bit? I know the On Load is in the property sheet, but how and where do I enter the Me.OpenArgs?
 
Not trying to step on HiTechCoach or anything...

However, below is yet another way of doing this.

If you are opening the new invoice using a button you could add the following code to the OnClick event of the button.

DoCmd.OpenForm "NAME_OF_FORM_TO_OPEN", acNormal, "", "", , acNormal
Forms![NAME_OF_FORM_TO_OPEN]![FIELD_NAME_ON_FORM_TO_BE_OPENED] = Me.[FIELD_NAME_ON_FORM_WITH_BUTTON]

Replace the items in RED with your form and field names...

Hope this helps...

Don
 
Don,

Thanks for the response. I should have mentioned up front that I'm using Access 2007, it doesn't create buttons with VBA, it creates macros. Can this code be used in a macro some how? I tried making my own module with your code, but it did nothing when I clicked on the button.
 
If you want to have the macros converted to code...It's actually easy to do.

While in design mode of the form - click on Database Tools on the ribbon

Then on the left side click on Convert Form's Macros to Visual Basic (this will convert all macros in the current form to code)

Don
 
Don,

That's AWESOME! It works like a charm. Thank you so much!!

Scott
 
Ok i am also new to Access and form programming. Here is what i want to setup.

I have four fields on a form, Staff Last Name, Staff First Name, Vehicle Owner Last Name, Vehicle Owner First Name.

I want to have code that does the following.

On Vehicle Owner Last Name Focus if it is blank autofill it with Staff Last Name.
On Vehicle Owner First Name Focus if it is blank autofill it with Staff First Name.

What would be my code to accomplish such a task? Thank you so much in adavance.
 

Users who are viewing this thread

Back
Top Bottom