Question Locked

Referencing result of running a Select query in Access VBA code

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm teaching myself Access VBA and I'm stumped. I want to execute code depending on if a record has already been entered in a table. Basically, if the record already exists, I want to update it. If it doesn't exist, I want to add it.

To accomplish this, I chose to execute a Select query where the record key equals what I'm looking for. If the query returns a NULL recordset, I know what to do.

How do I capture the ERR.Description that comes back when I get the NULL recordset on a "DoCmd.RunSQL XXXXX" command?

2 replies

by alec.wood

As above, new to database and teaching myself VBA same as you, but here's my best shot

DIM intErrorNum as Integer
ON ERROR GOTO errortrapthingy

errortrapthingy:
intErrorNum = ERR.Number
IF intErrorNum= THEN
do stuff
ELSE
MsgBox ERR.Description
EXIT SUB
END IF

This discussion is closed to new replies.