Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Dai Tanaka   on Jan 28 In MS Office Category.

  
Question Answered By: Fuzairah Neeman    on Jan 28

Actually I figured it out for myself. There is no step 5 any more,
step 3 and 4 as below will update an existing record.

'Step 3: Build your SQL statement

MySQL = "UPDATE tblClientCodes Set tblClientCodes.[Client surname] =
'" & [Client1Surname].Value & "' WHERE (((tblClientCodes.[ClientID])=
'" & [ClientIdentifier].Value & "'))"


'Step 4: Instantiate and specify your recordset

Set MyRecordset = New ADODB.Recordset

MyRecordset.Open MySQL, MyConnect, adOpenStatic, adLockOptimistic


That won't actually do anything if it is a new record you are
creating. To add a new record you need to use INSERT instead of
UPDATE. Like so:

'Step 3: Build your SQL statement

MySQL = "INSERT INTO tblClientCodes (ClientID, [Client surname])
VALUES ('" & [ClientIdentifier].Value & "','" & [Client1Surname].Value
& "')"

'WHERE (((tblClientCodes.[ClientID])= '" & [ClientIdentifier].Value &
"'))"



'Step 4: Instantiate and specify your recordset

Set MyRecordset = New ADODB.Recordset

MyRecordset.Open MySQL, MyConnect, adOpenStatic, adLockOptimistic





Hope this helps. Next step I guess would be setting up a test to see
if the record exists, so it knows whether to use the UPDATE SQL or the
INSERT SQL.

But it appears that reading and writing from a database  to Excel is
actually pretty easy to do.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 


Tagged: