| Chat with a LIVE Microsoft
Access Expert! |
||||
|
||||
|
#1
|
|||
|
|||
|
Help with SQL code
I need a littlle help adapting this piece of code to my purposes:
SELECT Clientes.[Codigo Cliente LAE], Clientes.Nome, Clientes.Endereço, Clientes.Cidade, Clientes.[Codigo Postal], Clientes.Telefone, Clientes.Fax, Clientes.[Numero Contribuinte] FROM Clientes GROUP BY Clientes.[Codigo Cliente LAE], Clientes.Nome, Clientes.Endereço, Clientes.Cidade, Clientes.[Codigo Postal], Clientes.Telefone, Clientes.Fax, Clientes.[Numero Contribuinte] HAVING (((Clientes.[Codigo Cliente LAE]) Like "*" & Forms![Pesquisa de Clientes]!PCTextPesq2 & "*")); I need to replace "Codigo Cliente LAE" by "Forms![Pesquisa de Clientes]!PCComboPesq" (I need to keep the [] of the the original code, just replace "Codigo Cliente LAE"). I've tried several ways but still get a sintax error. Thanks in advance. |
| Sponsored Links |
|
#2
|
|||
|
|||
|
Code around it
There are two ways to do it, one automated and a little more complex, and one less automated but easier (depending on your skill level).
The easier way is to make what you need to replace a parameter. Then you get prompted for it each time you run the query. It's not exactly automatic -- you have to enter the information into that box each time -- but it's very simple. (If you're not sure how to make a parameter value, search this forum.) The fully automatic way is to place the SQL into a table and then reference that table in code using a QueryDefs. This isn't as hard as it sounds.
Code:
strSQL = DLookup("SQL", "t_SQL", "SQL_Name='YOURQUERYNAMEHERE'")
strSQL = Replace(strSQL, "{CLIENTES}", Forms![Pesquisa de Clientes]!PCComboPesq)
CurrentDb.QueryDefs("YOURQUERYNAMEHERE").SQL = strSQL
Finally, make these change to your SQL (from your post) in the t_SQL table: Code:
SELECT Clientes.[{CLIENTES}], Clientes.Nome, Clientes.Endereço, Clientes.Cidade, Clientes.[Codigo Postal], Clientes.Telefone, Clientes.Fax, Clientes.[Numero Contribuinte]
FROM Clientes
GROUP BY Clientes.[{CLIENTES}], Clientes.Nome, Clientes.Endereço, Clientes.Cidade, Clientes.[Codigo Postal], Clientes.Telefone, Clientes.Fax, Clientes.[Numero Contribuinte]
HAVING (((Clientes.[{CLIENTES}]) Like "*" & Forms![Pesquisa de Clientes]!PCTextPesq2 & "*"));
Hope that helps. ~Moniker Last edited by Moniker; 12-23-2006 at 05:02 PM.. |
|
#3
|
|||
|
|||
|
Thanks! I tried the second way and it worked great!
![]() |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding comments into SQL code | inoxo | Queries | 6 | 12-20-2005 08:43 AM |
| SQL Query: Having 'OR' clause causes problems | rusco | Queries | 3 | 11-20-2004 08:26 PM |
| Creating A Link To Sql Server Table In Code | jaydwest | Modules & VBA | 0 | 09-29-2004 06:56 PM |
| SQL code: UDATE..SET date values? | jadeIT | Modules & VBA | 5 | 08-02-2002 08:16 PM |
| Refresh the links of tables to the SQL server backend through code | reena | Modules & VBA | 1 | 04-25-2002 09:01 PM |