Hi All,
On this lovely Friday just before leaving for the weekend, I began getting a run-time error, cannot be a zero-length. After about 30 minutes, I isolated the problem to the linked table named [Codes]. If I import codes to the front end from the back end, the vba behind the form works perfect. After I delete the table from the front end and re-link the table to the back end, it produces the error.
Again, this error is not produced if imported to the front end. But since the database is shared on the network, I need it linked.
Any suggestions as to why? Below is the code I am using for the form. Attached is the error message.
On this lovely Friday just before leaving for the weekend, I began getting a run-time error, cannot be a zero-length. After about 30 minutes, I isolated the problem to the linked table named [Codes]. If I import codes to the front end from the back end, the vba behind the form works perfect. After I delete the table from the front end and re-link the table to the back end, it produces the error.
Again, this error is not produced if imported to the front end. But since the database is shared on the network, I need it linked.
Any suggestions as to why? Below is the code I am using for the form. Attached is the error message.
Code:
Option Compare Database
Function NewRequisitionNumber() As String
Dim startRange_Var As Long, lastNum_Var As Long, yearValue_Var As Long
On Error GoTo Err_Execute
'Retrieve last number assigned for Requisition Number
codeDesc_Var = Nz(DLookup("Code_Desc", "Codes"), 0)
lastNum_Var = Nz(DLookup("Last_Nbr_Assigned", "Codes"), 0)
startRange_Var = Nz(DLookup("StartingRange", "Codes"), 0)
yearValue_Var = Nz(DLookup("YearValue", "Codes"), 0)
Set DB = CurrentDb()
Set rstsource = DB.OpenRecordset("Codes", dbOpenTable)
'If no records were found, create a new Requisition Number in the Codes table
'and set initial value to 1
If lastNum_Var = -1 Then
codeDesc_Var = Nz(DLookup("Code_Desc", "Codes"), 0)
yearValue_Var = Nz(DLookup("YearValue", "Codes"), 0)
startRange_Var = Nz(DLookup("StartingRange", "Codes"), 0)
lastNum_Var = Nz(DLookup("Last_Nbr_Assigned", "Codes"), 0)
Set DB = CurrentDb()
Set rstsource = DB.OpenRecordset("Codes", dbOpenTable)
'New Requisition Number is formatted as "LRS-12-60001", if year is 2012 for example
LNewRequisitionNumber = codeDesc_Var & "-" & yearValue_Var & "-" & startRange_Var + lastNum_Var
Else
'Determine new Requisition Number
'New Requisition Number is formatted as "LRS-12-60001", if year is 2012 for example
LNewRequisitionNumber = codeDesc_Var & "-" & yearValue_Var & "-" & startRange_Var + lastNum_Var
'Debug.Print (CLng(startRange_Var) + CLng(lastNum_Var))
'Increment counter in Codes table by 1
LUpdate = "UPDATE Codes SET Last_Nbr_Assigned = " & lastNum_Var + 1
CurrentDb.Execute LUpdate, dbFailOnError
End If
NewRequisitionNumber = LNewRequisitionNumber
Exit Function
Err_Execute:
'An error occurred, return blank string
NewRequisitionNumber = ""
Call MsgBox("An error occurred while trying to determine the next Requisition Number to assign." & Chr(10) & Err.Description, vbCritical)
End Function