Access BTN Macro Update Query to VBA

Mac1206

Board Regular
Joined
Jun 3, 2016
Messages
184
Hi, I have a Button Update query that I would like to convert to VBA OnClick but not quite sure how to actually make this happen....

This is the actually query:
UPDATE DistTable SET DistTable.Moved = True,
DistTable.MovedBy = [Forms]![HomePage]![Subform_User].[Form]![User],
DistTable.MovAmt = [TotalCollected],
DistTable.MoveDt = Date(),
DistTable.Completed = True

WHERE (((DistTable.Moved)=False)
AND ((DistTable.Completed)=False)
AND ((DistTable.Platform)="TS")
AND ((DistTable.Excluded)=False));




My VBA Code:
Private Sub BtnMMMComplete_Click()

Dim strSQL As String

strSQL = "UPDATE DistributionTable SET Me.Moved = 'True'" & _
"Me.Moveby = '[Forms]![HomePage]![Subform_User].[Form]![User]'" & _
"Me.MoveAmt = '[TotalCollected]'" & _
"Me.MoveDT = Date" & _
"Me.Completed = 'True'" & _
"WHERE Me.Moved = 'False'" & _
"AND Me.Completed = 'False'" & _
"AND Me.Platform = 'TS'" & _
"AND Me.Excluded = 'False'"

DoCmd.RunSQL



End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
if you put this above sql into an actual query , say "quUpdMyData"

then the code would be:
Code:
sub btnSave_click()
docmd.openquery "quUpdMyData"
end sub
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

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