Max Query And Module

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top