[AccessD] Updating a specific record using VBA.

Jurgen Welz jwelz at hotmail.com
Wed Oct 22 21:42:31 CDT 2008


CurrentDb.Execute ("Update tmpUseOneProdCode Set APLIDLoadedNumber= " & lngAPLID & _
    ", APLIDLoadedDesc= '" & strProgName & "', APLIDasString= '" & strAPLID & _
    "' Where KeyID = " & lngMyKeyID)
or you could open a recordset on the record with a where clause stipulating KeyID = lngMyKeyID, then
With gDAOrs    .Edit
    .Fields("APLIDLoadedNumber").Value = lngAPLID    .Fields("APLIDLoadedDesc").Value = strProgName    .Fields("APLIDasString").Value = strAPLID    .UpdateEnd With. 
The first example could use a DAO database object variable and a string variable for the sql string.  If you create a database object, you may check the database variable .RecordsAffected property to be sure that a record was found and updated.
 
Looks like this is a temp table with one record?
CiaoJürgen WelzEdmonton, Albertajwelz at hotmail.com> From: Darryl.Collins at coles.com.au> To: accessd at databaseadvisors.com> Date: Thu, 23 Oct 2008 11:28:49 +1100> Subject: [AccessD] Updating a specific record using VBA.> > Bah! I have asked this before but I cannot find the answer in the archives. and it is sooo darn simple too.> > Sorry for repeating this.> > I have code like this which writes new records into a table - easy:> '--------------------------------------------------------------------------------------------------------> Set gDAOrs = gDAOdb.OpenRecordset("tmpUseOneProdCode", dbOpenTable)> > With gDAOrs> .AddNew> .Fields("APLIDLoadedNumber").Value = lngAPLID> .Fields("APLIDLoadedDesc").Value = strProgName> .Fields("APLIDasString").Value = strAPLID> .Update> End With> > '--------------------------------------------------------------------------------------------------------> > What I want is to update an existing record, rather than add a new one.> Something Like:> > With gDAOrs> .Update KeyID = lngMyKeyID> .Fields("APLIDLoadedNumber").Value = lngAPLID> .Fields("APLIDLoadedDesc").Value = strProgName> .Fields("APLIDasString").Value = strAPLID> .Update> End With.> > Can someone please help with the syntax on this.> > Cheers> Darryl.
_________________________________________________________________




More information about the AccessD mailing list