B
Bryan Hughes
Hello,
I have a Query that is run in a global module that finds the last ID number
entered in a case file and and adds 1 to and returns the results.
I was working is now not working. I do not now what I am doing wrong
Here is the module function:
'*******************************************************
'Get last Client Number ID Number entered for Case File
'if this is first client in case file return 1
Public Function GetCNID(strCFID As String) As Integer
On Error GoTo ErrorHandler
strSQL = "SELECT CNID FROM tblClient_Details WHERE CFID='" & strCFID & "' "
strSQL = strSQL & "And CNID IN (SELECT MAX(CNID) FROM tblClient_Details);"
'Set db and recordset variables for DAO
Set dbs = CurrentDb()
Set rst1 = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
With rst1
If Not .EOF Then
.MoveLast
intLastCNID = !CNID
intNewCNID = intLastCNID + 1
Else
intNewCNID = 1
End If
End With
rst1.Close
dbs.Close
GetCNID = intNewCNID
Set rst1 = Nothing
Set dbs = Nothing
Exit Function
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Function
This how I call the Function from form module
Set txt = Me![txtCNID]
txt = GetCNID(strCFID)
intCNID = Me.txtCNID.Value
Please Help!
-Bryan
I have a Query that is run in a global module that finds the last ID number
entered in a case file and and adds 1 to and returns the results.
I was working is now not working. I do not now what I am doing wrong
Here is the module function:
'*******************************************************
'Get last Client Number ID Number entered for Case File
'if this is first client in case file return 1
Public Function GetCNID(strCFID As String) As Integer
On Error GoTo ErrorHandler
strSQL = "SELECT CNID FROM tblClient_Details WHERE CFID='" & strCFID & "' "
strSQL = strSQL & "And CNID IN (SELECT MAX(CNID) FROM tblClient_Details);"
'Set db and recordset variables for DAO
Set dbs = CurrentDb()
Set rst1 = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
With rst1
If Not .EOF Then
.MoveLast
intLastCNID = !CNID
intNewCNID = intLastCNID + 1
Else
intNewCNID = 1
End If
End With
rst1.Close
dbs.Close
GetCNID = intNewCNID
Set rst1 = Nothing
Set dbs = Nothing
Exit Function
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Function
This how I call the Function from form module
Set txt = Me![txtCNID]
txt = GetCNID(strCFID)
intCNID = Me.txtCNID.Value
Please Help!
-Bryan