Hey everyone,
Here is what I am trying to do, and have stumbled on hurdles. I have attached pictures of the form, and inserted my attempted coding below.
1. User opens form to log in a quantity of chemicals received.
2. User selects a catalog # from drop down box and the selection fills in the Chemical Name information (this is purely a visual representation for the user, I have locked all data entry on the left side of the form, except for Lot Number).
3. User starts to enter the received date, expiration date, etc. etc. on the right side of the form.
4. User enters the number of containers at the bottom of the form, to enter the same chemical information for that many records, and then clicks Add Chemical(s) or Close Form buttons (close only if there is one chemical container to log in)
---Preferably when the user clicks the Add Chem or Close Form button, I need the control "Chemical ID" to generate the year followed by the next sequential number, i.e. 2012-0001. I need the year to represent the system year (so that it changes every year), and the sequential number to both increase throughout that year, and then start over at 1 the next year (and also be in the format of 0001, so 2013-0001, 2014-0001, etc.) And since there could be multiple containers entered on the Log In form, I also need the "Chemical ID" to increment that many times, i.e. 2013-0026 through 2013-0030 for 5 chemical containers.
I have attempted to modify June7's code from the following post: http://forums.aspfree.com/microsoft-...ta-403208.html...here is my coding:
Code:
Public Function GetNewChemicalID() As String
Dim strChemicalID As Stringstr
ChemicalID = Nz(DMax("ChemicalID", "tblChemicalID"), "")
If strChemicalID <> "" Then
If Left(strChemicalID, 4) = CStr(Year(Date)) Then
GetNewChemicalID = Left(strChemicalID, 6) & Format(Right(strChemicalID, 4) + 1, "0000")
Else
GetNewChemicalID = Year(Date) & "-0001"
End If
Else 'this accommodates very first generated number of blank database
GetNewChemicalID = Year(Date) & "-0001"
End If
End Function
I placed that coding into a module (not sure if that is part of the problem)
And then the second portion I placed in a After_Update event for Received Date (but I will be putting it on the Click event for my buttons).
Code:
Private Sub Received_Date_AfterUpdate()
Dim strChemicalID As String
'search for aborted ChemicalID and use it, else if none then
GetNewChemicalIDstrChemicalID = Nz(DLookup("ChemicalID", "tblChemicalID", "IsNull(Date_Received)"), "")
DoCmd.SetWarnings False
If strChemicalID <> "" Then
DoCmd.RunSQL "UPDATE tblChemicalID SET Date_Received=#" & Date & "# WHERE ChemicalID='" & strChemicalID & "'"
Else
strChemicalID = GetNewChemicalID()
DoCmd.RunSQL "INSERT INTO tblChemicalID (ChemicalID, Date_Received) VALUES ('" & strChemicalID & "', #" & Date & "#)"
End If
DoCmd.SetWarnings True
Me.ChemicalID.SetFocus
DoCmd.OpenForm "frmLogIn", acNormal, , "ChemicalID='" & strChemicalID & "'", , , strChemicalID & "," & "frmLogin"
End Sub
I receive a compile error stating that strChemicalID was expecting a variable or function, not a module.
Thoughts, suggestions, or modifications would be greatly appreciated. Here a copy of my form as well:
