SQL

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Can anyone show me how to create a select query using SQL and running it? I know I can't use DoCmd.RunSQL?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
What do you want as an out come? create a query in the database and open it?

from help for A97

Code:
Sub NewQuery()
	Dim dbs As Database, qdf As QueryDef, strSQL As String

	' Return reference to current database.
	Set dbs = CurrentDb
	strSQL = "SELECT * FROM Employees WHERE [HireDate] >= #1-1-93#"
	' Create new query.
	Set qdf = dbs.CreateQueryDef("RecentHires", strSQL)
	DoCmd.OpenQuery qdf.Name
	Set dbs = Nothing
End Sub

HTH

Peter
 
Upvote 0
I have to do an integrity check on some data. If the number of records produced from the query is 0, then I'm OK.

Thanks for the code. I'll try it and repost if I have a problem.
 
Upvote 0

Forum statistics

Threads
1,221,710
Messages
6,161,445
Members
451,706
Latest member
SMB1982

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