S
Stephen English
I am trying to write a function to update the next number in a table (e.g for
an invoice)
I want to have parameters of table and field name
My question is how do I refer to the field name in a recordset please?
I am sure it is easy and I am just having a mental block!
Thanks for any help you can provide
Stephen
GetNextNo("SysTbl_PO", "ID")
Public Function GetNextNo(strTable As String, strFld As String) As Long
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim lngNext As Long
Set db = CurrentDb
strSQL = "SELECT " & strFld & " FROM " & strTable
Set rs = db.OpenRecordset(strSQL)
If Not rs.EOF Then
rs.MoveFirst
With rs
.Edit
Problem is in next two lines!
lngNext = CLng(! & strFld)
' (rs! & strfld) = lngnext +1
.Update
End With
GetNextNo = lngNext
End If
End Function
an invoice)
I want to have parameters of table and field name
My question is how do I refer to the field name in a recordset please?
I am sure it is easy and I am just having a mental block!
Thanks for any help you can provide
Stephen
GetNextNo("SysTbl_PO", "ID")
Public Function GetNextNo(strTable As String, strFld As String) As Long
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim lngNext As Long
Set db = CurrentDb
strSQL = "SELECT " & strFld & " FROM " & strTable
Set rs = db.OpenRecordset(strSQL)
If Not rs.EOF Then
rs.MoveFirst
With rs
.Edit
Problem is in next two lines!
lngNext = CLng(! & strFld)
' (rs! & strfld) = lngnext +1
.Update
End With
GetNextNo = lngNext
End If
End Function