dbTalk Databases Forums  

Run a Select query in VBA Access

comp.databases comp.databases


Discuss Run a Select query in VBA Access in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sandrino1977@inwind.it
 
Posts: n/a

Default Run a Select query in VBA Access - 02-05-2004 , 03:07 AM






Hi all,

I'm trying to run a select query in VBA Access.

May I use the Docmd.Runsql (strSql) or it is only for Action queries?

Thak you very much.

Cheers

Reply With Quote
  #2  
Old   
Bob Hairgrove
 
Posts: n/a

Default Re: Run a Select query in VBA Access - 02-05-2004 , 05:17 AM






On 5 Feb 2004 01:07:53 -0800, sandrino1977 (AT) inwind (DOT) it
(sandrino1977 (AT) inwind (DOT) it) wrote:

Quote:
Hi all,

I'm trying to run a select query in VBA Access.

May I use the Docmd.Runsql (strSql) or it is only for Action queries?

Thak you very much.

Cheers
You could use RunSQL, but it won't do you much good for a "select"
query.

What is it that you really want to do?


--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com


Reply With Quote
  #3  
Old   
sandrino1977@inwind.it
 
Posts: n/a

Default Re: Run a Select query in VBA Access - 02-12-2004 , 11:12 AM



Hi Bob,

I started defining some variable as strings in order to declare the
Sql statement. Then I run the Sql Statement through the function
Docmd. RunSQL by using the variable strSQL as argument.

Anyway, it doesn't work.

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click


Dim StrSQL As String
Dim strSelect As String
Dim strFrom As String
Dim strWhere As String
Dim RagSoc As String


RagSoc = ComboRagSoc.Value


strSelect = "[Operazioni Tassi].[Codice Azienda], [Operazioni
Tassi].[Nozionale], [Sottostante].[Tipo], [Operazioni Tassi].[Partenza
Copertura], [Operazioni Tassi].[Scadenza Copertura], [Operazioni
Tassi].[Ammortamento]"
strFrom = "Sottostante RIGHT JOIN ([Lista Aziende] RIGHT JOIN
(Divisa1 RIGHT JOIN [Operazioni Tassi] ON [Divisa1].[Codice
divisa]=[Operazioni Tassi].[Codice Divisa]) ON[Lista Aziende].[Codice
azienda]=[Operazioni Tassi].[Codice Azienda]) ON [Sottostante].[Codice
sottostante]=[Operazioni Tassi].[Codice Sottostante]"
strWhere = "((([Operazioni Tassi].[Codice Azienda])='" & RagSoc &
"'))"

StrSQL = "SELECT " & strSelect & " FROM " & strFrom & " WHERE " &
strWhere

Docmd.RunSQL StrSql

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub








Bob Hairgrove <wouldnt_you_like (AT) to_know (DOT) com> wrote

Quote:
On 5 Feb 2004 01:07:53 -0800, sandrino1977 (AT) inwind (DOT) it
(sandrino1977 (AT) inwind (DOT) it) wrote:

Hi all,

I'm trying to run a select query in VBA Access.

May I use the Docmd.Runsql (strSql) or it is only for Action queries?

Thak you very much.

Cheers

You could use RunSQL, but it won't do you much good for a "select"
query.

What is it that you really want to do?

Reply With Quote
  #4  
Old   
Bob Hairgrove
 
Posts: n/a

Default Re: Run a Select query in VBA Access - 02-12-2004 , 03:26 PM



On 12 Feb 2004 09:12:23 -0800, sandrino1977 (AT) inwind (DOT) it
(sandrino1977 (AT) inwind (DOT) it) wrote:

Quote:
Hi Bob,

I started defining some variable as strings in order to declare the
Sql statement. Then I run the Sql Statement through the function
Docmd. RunSQL by using the variable strSQL as argument.

Anyway, it doesn't work.
You're right ... sorry, my mistake. RunSQL is only for action queries.

Anyway, you could use OpenQuery ... but I still don't understand why.


--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com


Reply With Quote
  #5  
Old   
NB
 
Posts: n/a

Default Re: Run a Select query in VBA Access - 02-17-2004 , 10:03 PM



I don't have time to dig in your question right now. But it seems
comp.databases.ms-access is THE group to post this sort of questions
NB

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.