How to get record ID of just inserted record

W

wazza_c12

OK This is probably the easiest question ever, but I've been sitting at
the computer too long.

For some unknown reason my inset query that is called from an unbound
form will not work if a hyperlink field has more than 128 characters in
it.

If I do a VB insert command from the code page of the form, the
hyperlink works just fine.

So can I insert all but the hyperlink field by calling a query, then
get the record ID and update it with my hyperlink.

How do I get the record ID that was just added?

Yes this is messy, but I couldnt work out the original hyperlink
problem.

Please Help

Cheers

Wazza
 
G

Guest

I'd add a Date/Time field to the table and make the default value =Now().
Then you could do a query on the Max of the date field and find the latest
record.
 
R

RoyVidar

(e-mail address removed) wrote in message
OK This is probably the easiest question ever, but I've been sitting at
the computer too long.

For some unknown reason my inset query that is called from an unbound
form will not work if a hyperlink field has more than 128 characters in
it.

If I do a VB insert command from the code page of the form, the
hyperlink works just fine.

So can I insert all but the hyperlink field by calling a query, then
get the record ID and update it with my hyperlink.

How do I get the record ID that was just added?

Yes this is messy, but I couldnt work out the original hyperlink
problem.

Please Help

Cheers

Wazza

With Jet 4.0, you can use "select @@identity" on native tables on the
same connection as you've used for the insert.

dim cn as adodb.connection
dim rs as adodb.recordset
set cn = currentproject.connection
cn.execute "insert into ....",,adcmdtext+adexecutenorecords
set rs = cn.execute("select @@identity",,adcmdtext)
msgbox rs.fields(0).value

I'm sure there are DAO equivalents of this, too.
 

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