I need to find the maximum value of field IDPost (integer) and then icrease this value by 1, using code. I then declare this value as maxIDPost1 and use it on a form.
qryFindMaxIDPost is the query that gives all the numbers from where I will select the one that has the maximum value.
This is what I wrote:
Dim dbMax As Database, rsMax As Recordset
Dim sqlMax As String
Dim maxIDPost, maxIDPost1 As Integer
Set dbMax = CurrentDb
sqlMax = "SELECT IDPost " & _
"from qryFindMaxIDPost "
Set rsMax = dbMax.OpenRecordset(sqlMax, dbOpenSnapshot)
If Not rsMax.EOF Then
rsMax!IDPost = maxIDPost
maxIDPost1 = maxIDPost + 1
Me.maxIDPost1 = maxIDPost1
End If
What I don't know is where to put a line instructing the selection of the maximum value.
I would appreciate any help this question.
qryFindMaxIDPost is the query that gives all the numbers from where I will select the one that has the maximum value.
This is what I wrote:
Dim dbMax As Database, rsMax As Recordset
Dim sqlMax As String
Dim maxIDPost, maxIDPost1 As Integer
Set dbMax = CurrentDb
sqlMax = "SELECT IDPost " & _
"from qryFindMaxIDPost "
Set rsMax = dbMax.OpenRecordset(sqlMax, dbOpenSnapshot)
If Not rsMax.EOF Then
rsMax!IDPost = maxIDPost
maxIDPost1 = maxIDPost + 1
Me.maxIDPost1 = maxIDPost1
End If
What I don't know is where to put a line instructing the selection of the maximum value.
I would appreciate any help this question.