Change Access Entry using Excel VBA

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
Hi guys,

How do I change a certain entry in an Access table using Excel VBA?

Thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi

You will need to be much much more specific. Which records do you need to amend? I mean based on what rules?
 
Upvote 0
Hi guys,

How do I change a certain entry in an Access table using Excel VBA?

Thanks

As Jon has stated you would need to give more details. You can use the Update query SQL code.

So if you can give more information then you will get a better response.
 
Upvote 0
Hi

You will need to be much much more specific. Which records do you need to amend? I mean based on what rules?

Ok, I got a listbox where I read out values from the database, the user will select a value and can choose to edit it.
I will then query with the values and get the unique key (ID) as a recordset (at least that's what my plan was).
Having that ID, I will then select the entire data entry and give the user the possibility to edit it.

Does it make sense?
 
Upvote 0
If it's just the SQL you need, then as example:

Code:
    strSql = "UPDATE " & strTableName & _
             " SET " & strField & "=" & strValue & _
             " WHERE " & strID & "=" & CStr(lngKey) & ";"

This is a just a quick copy paste from one of my projects.

strTableName must refer to the name of the table that contains the records.
strField must refer to the field name that is to be updated.
strValue is the value you want it to be.
strID is the name of the ID field (primary key, usually)
lngKey is the ID value for the record you want to update.
 
Upvote 0
Thanks, will try and report back.
I will probably not need the ID value then probably, I could just use the values from the listbox.
 
Upvote 0
Will it identify the record distinctly? Because I imagine you won't want to be updating other records with same field values.
 
Upvote 0
Oh and I suggest you use the Command.Execute method. You have no need to return a recordset.

Code:
Call command.Execute(RecordsAffected:=lngRecordsAffected, _
                             Options:=CommandTypeEnum.adCmdText Or ExecuteOptionEnum.adExecuteNoRecords)
 
Upvote 0

Forum statistics

Threads
1,216,462
Messages
6,130,781
Members
449,591
Latest member
sharmavishnu413

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top