|
-
Mar 6th, 2006, 07:00 AM
#1
Thread Starter
Member
SQL Query and Access
Hi Guys,
I want to use VBA to execute a query and return the results just like a normal Access query (ie: in a datasheet type view). How can I do this?
Shane
-
Mar 6th, 2006, 07:55 AM
#2
Re: SQL Query and Access
Same way as you would do it in VB.
Create a connection to the database using ADODB and execute the query.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Mar 6th, 2006, 08:33 AM
#3
Addicted Member
Re: SQL Query and Access
Search in google about ado. There are loads of code samples abd tutorials.
or
This should be helpful:
- http://msdn.microsoft.com/library/de...tlibraries.asp
hope this help,
regards,
sweet_dreams
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts. 
-
Mar 6th, 2006, 08:40 AM
#4
Frenzied Member
Re: SQL Query and Access
DAO (fastest for Access only operations):
DoCmd.RunSql "SELECT * FROM Foo"
or if it's a saved query in Access
DoCmd.OpenQuery "qryFoo"
ADO is different, uses .Execute, etc.
Tengo mas preguntas que contestas
-
Mar 6th, 2006, 06:16 PM
#5
Thread Starter
Member
Re: SQL Query and Access
DoCmd.RunSQL "SELECT * FROM mwo2005 WHERE Method='LIQUID'"
Gives error:
A RunSQL action requires an argument consisting of an SQL statement.
-
Mar 6th, 2006, 10:30 PM
#6
Thread Starter
Member
Re: SQL Query and Access
I have discovered that DoCmd.RunSQL cannot be select statements but havent found a way to extract information and display it in the same way as a saved query. Also, how do I reference a field value on a form?
Ie: frmMain.txtType.Text? for SELECT * FROM mwo2005 WHERE Method='" & ... & "'"
-
Mar 7th, 2006, 02:21 AM
#7
Re: SQL Query and Access
You can access control values like so.
VB Code:
SELECT * FROM mwo2005 WHERE Method='" & Forms![Form1].txtType.Value & "'"
Only these types of queries can be run with RunSQL...
Code:
Query type SQL statement
Action
---------------------------
Append INSERT INTO
Delete DELETE
Make-table SELECT...INTO
Update UPDATE
Data-definition (SQL-specific)
Create a table CREATE TABLE
Alter a table ALTER TABLE
Delete a table DROP TABLE
Create an index CREATE INDEX
Delete an index DROP INDEX
To run a basic SELECT SQL statement you will need to use the .OpenQuery function of a saved query.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2006, 10:16 AM
#8
Frenzied Member
Re: SQL Query and Access
Duh! I actually knew that and just wasn't thinking. Sorry for the misinfo, shane.
Tengo mas preguntas que contestas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|