2

I'm working with Access and I have many queries in the code like

"SELECT something, something " _
& "FROM the_table " _
& "WHERE something Is Null "

or

"SELECT " & _
  "Min(something), " & _
  "Max(something2) " & _
"FROM (the_table " & _
      "INNER JOIN another_table ON sm1 = sm2) " & _
"WHERE sm3 is not null " & _
      "AND sm4 = " & Me.plan

I want to do a macro that converts theses string to executable queries (delete initial quotes and final quotes, ampersands and undescores) and viceversa, convert queries to a string concatenation.

Example output would be:

SELECT
  Min(something),
  Max(something2)
FROM (the_table
      INNER JOIN another_table ON sm1 = sm2)
WHERE sm3 is not null
      AND sm4 = Me.plan

I don't know how to google this :S cause I'm asking.

I know how to record Macros on TextMate or similar, but I'm not familiar with it and I need some help.

Any tips? Thanks :-)

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
rubdottocom
  • 8,110
  • 10
  • 39
  • 59

1 Answers1

0

You can probably use DoCmd.RunSQL myString command.

See here and there for more valuable information

Btw, here is the Google Search you could have done: http://tinyurl.com/3apsala

JMax
  • 26,109
  • 12
  • 69
  • 88
  • xDDD first, the link doing an automatic google search is amazing! Second, I don't want execute sql strings inside an access application, I know how to do that! I want this macro to test and "play" with the queries in a SQLServer Management Studio to learn what is the app doing. – rubdottocom Sep 07 '11 at 07:54
  • OK, I see that Inmediate window on Acces is very interesting, do you know if I can execute queries stored in variables? I see RunSQL only tuns Create/Update/Insert/Delete and OpenQuery is for queries stored in database not strings with the query inside. – rubdottocom Sep 07 '11 at 08:08
  • playing with inmediate window I see that print "SQL string variables" and paste it to SQL Console is the quicker action I can do to test queries :P – rubdottocom Nov 22 '11 at 08:22