Hi all,
I'm new to the forum and to Access. I need help on how to use a Form to Make entries on a Table. I was able to create the form from the Table. On the form, I only have the fields I need to make a new entry on the Table and a button with VBA code to generate a sequential ID number (SIN) on the second column. So a few thing are not working fine.
When I click on the button, the VBA code generates the SIN but I'm not able to see it on the form. I thought this was just because the cell was on edit mode. However, if I move to the another fields on the form a plug in some data, I can actually see the data I type in, but the SIN is still not visible. After typing in the data and closing the form, I open the Table and I see that the SIN is there in a row but the data that I typed in for that record is in the next row. That defeats the purpose of the form which is create a new record in a single row with a custom SIN.
Can someone point me into the right direction?
Below is the VBA code I'm using to generate the sequential ID number (CaseId).
Code:
Private Sub Command13_Click()
Dim strCaseNum As String
'search for aborted case number and use that record, else if none then create new record
strCaseNum = Nz(DLookup("CaseId", "ObsoCases", "IsNull(Created)"), "")
If strCaseNum <> "" Then
CurrentDb.Execute "UPDATE ObsoCases SET Created=#" & Date & "# WHERE CaseId='" & strCaseNum & "'"
Else
strCaseNum = Nz(DMax("CaseId", "ObsoCases"), "")
If strCaseNum = "" Then
'this accommodates very first generated number of blank database
strCaseNum = Format(Date, "yy") & "-0001"
Else
'this accommodates change in year
If Left(strCaseNum, 2) = CStr(Format(Date, "yy")) Then
strCaseNum = Left(strCaseNum, 3) & Format(Right(strCaseNum, 4) + 1, "0000")
Else
strCaseNum = Format(Date, "yy") & "-0001"
End If
End If
CurrentDb.Execute "INSERT INTO ObsoCases(CaseId, Created) VALUES('" & strCaseNum & "', #" & Date & "#)"
End If
End Sub
Thanks,
The Newbie