auto populate of field after button is clicked

Bilal

Registered User.
Local time
Today, 11:26
Joined
Sep 30, 2013
Messages
64
i've got a data entry form.
when i click the button add all the other buttons go grey, i am in mode "New" also i am able to add, edit, records in this state, when i press save i want the supplierID field to automatically populate itself with the next SupplierID record THAT IS EMPTY.
So say that my last record was ID number 45 then when i click add on my form and go into "New" state the SupplierID field automatically populates itself with "46"
btw this is all an unbound form, if anyone can help me it will be greatly appreciated :) i will supply you with code or my database upon request
 
Is SupplierID an autonumber field? If so, you can't accurately guess 100% of the time the next ID it will generate. If it is not an autonumber but a numeric field you will populate yourself when the Save button is clicked, then you can use the DMax function (http://www.techonthenet.com/access/functions/numeric/max.php) and add one to that.
 
can you help me solve two things please?
i got two fields in my form that i am dealing with (these two fields are not working and giving me too much problems) the first one is supplierID this is a autonumber field and second is personID this is a numeric field and a foreign key, these both fields i have to enter the numbers in myself for it to correctly work, i can not leave the field empty or it just wont work, i shouldnt have to do that with ID fields.
If so, you can't accurately guess 100% of the time the next ID it will generate.
this is really confusing me, if its a autonumber the number will just ascend right? so 10% of the time it will always be the next number up.

Thanks very much for taking time out to help me :)
Bilal
 
You asked about 2 things, but I don't see what they are, so let me extrapolate about autonumbers:

An autonumber is guaranteed to produce a new unique numeric value for a new record--nothing more. Yes, I've never seen Access produce a new value lower than an existing one. However, I've witnessed many times where the "next" autonumber value wasn't just 1 more than the highest value already in the table. You'll find many posts on this forum who assumed that, built logic around that assumption and then got into unresolvable issues when they found out the autonumber didn't always behave that way.

Why must you display the ID number on this form? Why are you using an unbound form?
 
Firstly i am only displaying the ID on the form for my reference, until i get it right, then i can easily make it invisible with a few clicks,
secondly, it is unbound because im playing around trying to accustom myself with unbound forms, i can easily do bound.
If you have a look at my attachment and familiarize yourself with the vba code on frmSupplier. i got a subform, thats not working yet because i dont want to run the form in an inconsistent state and im trying to get the main form to work properly first.
essentially, what is mean to hapen is that when i toggle through my suppliers all the information linking to them in the subform should also come up, my main problem at the moment is the save button, and saving a completely new record
 

Attachments

Autonumbers always ascend unless you have Replication on, in which case it'll be some bizarre 12-digit number that could be positive or negative according to the RNG. That's not likely what you're after here.

BUT... they will not always be sequential. If you start to edit your 12th record and then escape out of it, shut it down, go to lunch and your computer crashes, etc... the next time you open up Access your Autonumber will probably say 13. That's why plog is suggesting you use DMax for your sequential numbering, and let the autonumber take care of the Primary Key responsibilities it was designed for.

You should be able to use the Form_Insert event to check DMax and autoinsert your next SupplierID.
 
You have 573 lines of code on frmSupplier--I'm not going to familirize myself with it. In design view I see your buttons, but in regular view, they don't appear. I really don't know what you mean by 'toggle through my suppliers' as I see no way to change them on the form.

How is the subform not working? What should it be displaying? You might want to post this in the Forms section of this site--they aren't really my forte.
 
You have 573 lines of code on frmSupplier--I'm not going to familirize myself with it
hahahah that first line made me lol, i fixed it though, it was my .addnew .update .edit and .update which were jumbled around and i also had to get this line of code in; Me.SupplierID.Value = DLast("SupplierID", "tblSupplier")
thanks very much for helping me earlier also, god bless
Bilal
 

Users who are viewing this thread

Back
Top Bottom