Running a query in code

Michael Walker

New Member
Joined
Jan 13, 2005
Messages
8
Hi

How do I run a query (ie. append, select, delete) in code, without having to go through the yes no message box prompts?

Thanks Michael
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,432
Hi Michael
Try using the SetWarnings command, I think the code is
DoCmd.SetWarnings 0
to turn them off and
DoCmd.SetWarnings -1
to turn them back on. This will prvent modal warnings & message boxes from popping up but will not stop error messages.
HTH, Andrew. :)
 

jag108

Active Member
Joined
May 14, 2002
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=esmr.airnz.co.nz;UID=your ID/password;DBQ=Databse IP;ASY=OFF;", Destination:=Range("A1"))
.Sql = Array("SELECT SW_SERVICE_ORDER.SWSERVICEORDERID, SW_SERVICE_ORDER.AIRPARENTOBJECTID, SW_SERVICE_ORDER.SWNOTE, SW_SERVICE_ORDER.SWSTATUS," _
, " SW_SERVICE_ORDER.AIRBUSINESSIMPACT, SW_SERVICE_ORDER.AIRCUSTOMERIMPACT, SW_PERSON.AIRFULLNAME, SW_SERVICE_ORDER.SWDATECREATED" & Chr(13) & "" & Chr(10) & "FROM ESM.SW_PERSON SW_PERSON, ESM.SW_PROVIDER_GRP SW_PROVIDER_GRP, ESM.S" _
, "W_SERVICE_ORDER SW_SERVICE_ORDER" & Chr(13) & "" & Chr(10) & "WHERE SW_SERVICE_ORDER.SWREPORTEDBY = SW_PERSON.SWPERSONID AND SW_SERVICE_ORDER.SWPROVIDERGRPID = SW_PROVIDER_GRP.SWPROVIDERGRPID AND ((SW_SERVICE_ORDER.SWPRODRELEASE" _
, "ID In (3357,5020)) AND (SW_SERVICE_ORDER.SWSTATUS In ('Accepted','Assigned','In Progress','Logged','On Hold','On Monitor')) AND (SW_PROVIDER_GRP.SWNAME In ('Intl Ops - Logistics Support')))" & Chr(13) & "" _
, "" & Chr(10) & "ORDER BY SW_SERVICE_ORDER.SWDATECREATED")
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = False
.SaveData = True
End With
Format_sheet
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
jag108

Did you mean to post this in the Access forum?

Perhaps it's more suitable for the Excel forum.

And if that's right perhaps you could tell us what problem you have.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,259
Messages
5,600,575
Members
414,390
Latest member
plimbu

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