mcgregor123
Technical User
Hello. I hope I am posting this in the right place. I have a form that my people use to enter new records. I am in the process of changing how this form numbers the records. Currently it uses autonumbering, but that has caused some problems when we try to import records that have been archived off for a previous year. (The table is archived and emptied each year). We end up with two records with the same number, and that's a problem.
So, what I propose to do is something along the lines of have a tiny table with the highest number of last year. Then when they add a new record, if there are no records in the table, look at this tiny table, and add one, and use that for the record_ID. If there ARE records in the table, look at the max record_ID and add one.
My tables are RecordNumber to hold the last year's highest number, with one field HighNumber.txt.
My main table is TblMain and the field I want the number to go in is Record_ID.
I understand the basic flow, but don't know how to write the VBA. I know it needs to be an IF statement, but I'm not sure where it should occur. This form is called from another form, and right now, when it opens to a new record, I notice that the Autonumbered RecordID doesn't fill in until they start completing the form. I'd like my new record_ID to look like that as well.
If the record count in TblMain = 0
then
RecordID = tbl.RecordNumber.Highnumber.txt, Max, +1
else
RecordID = tbl.TblMain.RecordID, Max, +1
end if
I know this is completely wrong, but I just wanted to take a stab at it so you could see what I'm trying to do.
Right now, in my RecordID field, I have
=DMax("ASRID","Tbl_ASR_Main")+1
Which works fine, except it will start the numbering over every year. And I don't want that, for the reason I mentioned earlier.
So can anyone tell me how to make this work? Thank you for your help.
So, what I propose to do is something along the lines of have a tiny table with the highest number of last year. Then when they add a new record, if there are no records in the table, look at this tiny table, and add one, and use that for the record_ID. If there ARE records in the table, look at the max record_ID and add one.
My tables are RecordNumber to hold the last year's highest number, with one field HighNumber.txt.
My main table is TblMain and the field I want the number to go in is Record_ID.
I understand the basic flow, but don't know how to write the VBA. I know it needs to be an IF statement, but I'm not sure where it should occur. This form is called from another form, and right now, when it opens to a new record, I notice that the Autonumbered RecordID doesn't fill in until they start completing the form. I'd like my new record_ID to look like that as well.
If the record count in TblMain = 0
then
RecordID = tbl.RecordNumber.Highnumber.txt, Max, +1
else
RecordID = tbl.TblMain.RecordID, Max, +1
end if
I know this is completely wrong, but I just wanted to take a stab at it so you could see what I'm trying to do.
Right now, in my RecordID field, I have
=DMax("ASRID","Tbl_ASR_Main")+1
Which works fine, except it will start the numbering over every year. And I don't want that, for the reason I mentioned earlier.
So can anyone tell me how to make this work? Thank you for your help.