Hi,
I have read a lot of threads about this but I can't seem to find one exactly like what I am trying.
I have a form that is used for adding a single record only. The properties for Allow Edits and Deletions is No, Allow Additions is Yes. It works fine right now but I would like make the field "AnimalID" automatically be filled with the next available AnimalID upon opening so that the users don't have to figure out what the next available AnimalID is.
I made a button that will show the next available AnimalID in a msgBox through a query, but I don't know where to put this code so that it will fill the text box on my form as soon as I open the form. On load, Before Update?? do i need some sort of public variable for this???
Code for button/msgBox:
Code:
Private Sub Command0_Click()
Dim rst As New ADODB.Recordset
Dim str As Integer
Dim NextID As String
rst.Open "SELECT Max(Val(Right([AnimalID],3))) AS MaxAnimalID FROM Tbl_AnimalList;", CurrentProject.Connection
str = rst.GetString
NextID = "BH" & Format((str + 1), "000")
rst.Close
Set rst = Nothing
MsgBox NextID
End Sub
Also I am struggling with the line that sticks the value into the box.
The name and control source of the box is: Tbl_AnimalList_AnimalID
The name of the form is: Form_AddLamb
Form!Tbl_AnimalList_AnimalID.AnimalID = NextID