Link to home
Create AccountLog in
Avatar of kwarden13
kwarden13

asked on

Access Form - Auto Populate w/ current ID

I have a pop up form that a user can click on the supplier id from my main form. They can use this to add categories. How can I make it so the Supplier Name and ID will auto populate and all they have to do is select another category?
sample_3.241.accdb
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of kwarden13
kwarden13

ASKER

Yes it does stay open. I will try that Scott. Thanks
Scott, If you use the Open event for this purpose, you have two problems
1. It only works for a single record.
2. You dirty the form with code which will confuse the user if he tries to exit without saving.

Using the BeforeInsert works regardless of how many records you add in the popup and it does not dirty the form since this event would only run if the user had dirtied the form so presumably, he is intending to save or he will at least not be confused if he elects to exit without saving since he knows he typed something.

If you want the field to populate earlier, you could use the form's Dirty event but in that case, you would need to determine if this was a NewRecord or not since you would only want to do this for new records.
You dirty the form with code which will confuse the user if he tries to exit without saving.
My suggestion was just a way to retrieve the values from the calling form, not necessarily how to use them once you retrieved them. Once you did, you could certainly use those in the BeforeInsert event (just as you would use the values from your OpenArgs suggestion).

Just two different ways to get the values, I suppose.
If you need more than one field, the OpenArgs becomes difficult to use so referring to an open form is fine.  I just would never use the Open event because of the two things I mentioned.
I see what you mean - in my suggestion, you would ONLY have those variables during the Open event. A better idea would be to declare your variables like SupplierID at the Form level, and they'd be available for the duration of the form session, and you could use them anywhere.
@Scott,
I'm not sure why you are making work arounds to avoid using the BeforeInsert event.    When I have one argument to pass, I use OpenArgs.  When I have multiple, I refer to the calling form fields.  But in ALL cases, I use the BeforeInsert event because that event runs ONLY for new records and it runs for EVERY new record.  The BeforeInsert event runs once for every record you add.  The Open event runs only once, period - when the form opens.  Using the correct event eliminates problems rather than creating them.

If I wanted to pass in multiple values using the OpenArgs, I would decode the string in the Open event and save the individual arguments as TempVars.  But, I would still not apply the values there.  I would still use the BeforeInsert event and from there I would reference the TempVars.  Using the OpenArgs would be necessary if the "popup" form could be called from multiple main forms so that you couldn't directly reference form fields without knowing what form caused the "popup" to open.
I'm not avoiding the use of BeforeInsert.

I said nothing about avoiding the use of BeforeInsert.

I fully understand what and how BeforeInsert works.

My comment (as poorly worded as it is) involved RETRIEVING the values in the form's Open event, not RETRIEVING and USING them in the Open event. You could RETRIEVE them in the Open event, and then store them in a Form-level var, a Public var, TempVars, or anywhere else you choose - and you could then use those in the BeforeInsert event (or anywhere else your little heart desires).