Hi all,
I have a table with primary key p_id (autonumber)
Before I want to add something in this table (read: before I want to open an bound form) I want to insert the p_id into an other table. So I thought that when I click a button, access first finds the highest number, add 1, and use that nr to insert into the table.
This is the code I want to use to get the highest nr:
Dim dbs As DataBase
Dim rst As Recordset
Dim strSQL As String
Dim str As String
strSQL = "select max(p_id) from tbl_PERSOON;"
Set rst = dbs.OpenRecordSet(strSQL)
str = rst!p_id
DisplayMessage (str)
Set rst = Nothing
but on the line "Set rst = dbs.OpenRecordSet(strSQL)" access gives the error: (translated from dutch) "objectvariable or blockvariable With is not set"
what am I doing wrong? Is there an other way around this?
I have a table with primary key p_id (autonumber)
Before I want to add something in this table (read: before I want to open an bound form) I want to insert the p_id into an other table. So I thought that when I click a button, access first finds the highest number, add 1, and use that nr to insert into the table.
This is the code I want to use to get the highest nr:
Dim dbs As DataBase
Dim rst As Recordset
Dim strSQL As String
Dim str As String
strSQL = "select max(p_id) from tbl_PERSOON;"
Set rst = dbs.OpenRecordSet(strSQL)
str = rst!p_id
DisplayMessage (str)
Set rst = Nothing
but on the line "Set rst = dbs.OpenRecordSet(strSQL)" access gives the error: (translated from dutch) "objectvariable or blockvariable With is not set"
what am I doing wrong? Is there an other way around this?