You can use this in the Form_Current event procedure:
Dim strCompli As String
If IsNull(txtCompli_Num) = True Then
strCompli = DMax("Compli_Num", "YourTableName"
txtComli_Num = Left(strCompli, 4) & Format(CInt(Right(strCompli, 3)) + 1, "000"
End If
Now the text box on the form will be automatically filled in any time you go to a new record. Please note that you will need to do three things. One, you will need to make a way for the user to undo records which are started by accident. Two, you will need to make sure some information is in the table initiallly. And finally, you will need to have some sort of method for handling Compli_Num after 999 records.
When I add new data, the all data add in the table, but the new "Compli_num" not add in the table yet. Therefore, when I get another new form, the txtCompli_num still show that number. What happens? Any suggestion?
1) Ensure the text box: txtComli_Num is bound to the field: compli_num
2) Also - you may wish to run this code on the Before Insert event vs. current to ensure you do not override existing values.
Nancy is correct, I assumed that the text box would be bound to Compli_Num. Checking for the Null in the text box should make sure that no information is overwritten, but it would be wise to test it on dummy data at first to make sure it is working properly.
Thanks again. I got problem: when I open the form one time, the Compli_num auto_increament one time. If I open the form more times, the compli_num auto_increament more times.
Thanks alot.
The following are my codes:
Private Sub Form_Current()
Dim strCompli As String
Dim strFeedYear As String
strFeedYear = Format(DATE, "yy"
If IsNull(txtCNUM) = True Then
strCompli = DMax("COMPLI_NUM", "COMPLAINTS"
Here's another option - create a custom function (module) which returns the value and use it as the default value on the field bound to the Compli_num - then you will see it right away.
So the default value of Compli will be = FeedCompli()
The same problem as I first got. The Compli_num not really add in the table, therefore, the form still show the same compli_num, not auto_increament compli_num after I add new info.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.