Update Exisiting Access Table From Excel

nikimitsy

Board Regular
Joined
Jun 5, 2013
Messages
132
I have Been Stuck with being unable to update Access Database Table.



This is what I am trying to achieve:
1- Search Access Database table (Table3) where Field(ID) = cell value/text
2-Update Table Field(Time_out) with Now()
close access

this is what i have been able to compile but something is wrong

Code:
Sub update2()Dim accApp As Object
Dim strOrder As String, strCode As String
strOrder = "4424"
strCode = Now()
Dim SQL As String
SQL = "UPDATE [Table3] SET [Table3].Time_out = " & strCode & " WHERE "
SQL = SQL & "((([Table3].ID)=4424));"
Set accApp = CreateObject("Access.Application")
With accApp
    .OpenCurrentDatabase "C:\Signin-Database\DATABASE\Visitor_Info.accdb"
    .DoCmd.RunSQL
    .Quit
End With
Set accApp = Nothing
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

nikimitsy

Board Regular
Joined
Jun 5, 2013
Messages
132
Ok This is what i have come up with, and seems to work but the problem i have is that it updates the entire field(Time_out) with Now(), instead of locating and matching field(ID). If I remove the id and just add text to sql statement it works as it is supposed do...please any help much appreciated


Code:
Sub UpdateAccessDatabase()Dim accApp As Object
Dim SQL As String
Dim id
id = frm1.update.caption [B] 'which is actually just a number-4424[/B]
SQL = "UPDATE [Table3] SET [Table3].Time_out = " & "Now()" & " WHERE "
SQL = SQL & "((([Table3].ID)=id));"  [B]'if i remove id and place 4424, it will only then search for and replace Time_out in that row[/B]
Set accApp = CreateObject("Access.Application")
With accApp
    .OpenCurrentDatabase "C:\Signin-Database\DATABASE\Visitor_Info.accdb"
    .DoCmd.RunSQL SQL
    .Quit
End With
Set accApp = Nothing


End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,130,310
Messages
5,641,450
Members
417,210
Latest member
rins

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
Top