PC Review


Reply
Thread Tools Rate Thread

changing sql sentence in query via vba code

 
 
thread
Guest
Posts: n/a
 
      17th Dec 2006
Hi all,
I'm trying to find a way to change the sentece of the sql inside the
query via vba code
for now no clue

 
Reply With Quote
 
 
 
 
tina
Guest
Posts: n/a
 
      17th Dec 2006
try

CurrentDb.QueryDefs("QueryName").SQL = "type the entire SQL statement
here"

note that you have to set the SQL property of the QueryDef to a complete SQL
statement - you can't just change "bits and pieces" of it.

hth


"thread" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
> I'm trying to find a way to change the sentece of the sql inside the
> query via vba code
> for now no clue
>



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      17th Dec 2006
<picky>

CurrentDb.QueryDefs("QueryName").SQL = _
Replace(CurrentDb.QueryDefs("QueryName").SQL, "Table1", "Table2")

or, more efficiently,

Dim qdfCurr As DAO.QueryDef

Set qdfCurr = CurrentDb.QueryDefs("QueryName")
qdfCurr.SQL = Replace(qdfCurr.SQL, "Table1", "Table2")
</picky>




--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"tina" <(E-Mail Removed)> wrote in message
news:Sa9hh.221344$(E-Mail Removed)...
> try
>
> CurrentDb.QueryDefs("QueryName").SQL = "type the entire SQL statement
> here"
>
> note that you have to set the SQL property of the QueryDef to a complete
> SQL
> statement - you can't just change "bits and pieces" of it.
>
> hth
>
>
> "thread" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi all,
>> I'm trying to find a way to change the sentece of the sql inside the
>> query via vba code
>> for now no clue
>>

>
>



 
Reply With Quote
 
thread
Guest
Posts: n/a
 
      17th Dec 2006
thanks people,
i fould something more efficient for me,
i'm just placing the sql sentence inside of the recordsource form,saves
place of a query even

Douglas J. Steele лъб:
> <picky>
>
> CurrentDb.QueryDefs("QueryName").SQL = _
> Replace(CurrentDb.QueryDefs("QueryName").SQL, "Table1", "Table2")
>
> or, more efficiently,
>
> Dim qdfCurr As DAO.QueryDef
>
> Set qdfCurr = CurrentDb.QueryDefs("QueryName")
> qdfCurr.SQL = Replace(qdfCurr.SQL, "Table1", "Table2")
> </picky>
>
>
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "tina" <(E-Mail Removed)> wrote in message
> news:Sa9hh.221344$(E-Mail Removed)...
> > try
> >
> > CurrentDb.QueryDefs("QueryName").SQL = "type the entire SQL statement
> > here"
> >
> > note that you have to set the SQL property of the QueryDef to a complete
> > SQL
> > statement - you can't just change "bits and pieces" of it.
> >
> > hth
> >
> >
> > "thread" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Hi all,
> >> I'm trying to find a way to change the sentece of the sql inside the
> >> query via vba code
> >> for now no clue
> >>

> >
> >


 
Reply With Quote
 
tina
Guest
Posts: n/a
 
      17th Dec 2006
<pickier>

but if you can run the same SQL statement on two different tables by
changing only the table name, they must be identical but for the table name.
sounds to me like that should be one table, with a field to hold whatever
data is currently stored in the table name...


"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:(E-Mail Removed)...
> <picky>
>
> CurrentDb.QueryDefs("QueryName").SQL = _
> Replace(CurrentDb.QueryDefs("QueryName").SQL, "Table1", "Table2")
>
> or, more efficiently,
>
> Dim qdfCurr As DAO.QueryDef
>
> Set qdfCurr = CurrentDb.QueryDefs("QueryName")
> qdfCurr.SQL = Replace(qdfCurr.SQL, "Table1", "Table2")
> </picky>
>
>
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "tina" <(E-Mail Removed)> wrote in message
> news:Sa9hh.221344$(E-Mail Removed)...
> > try
> >
> > CurrentDb.QueryDefs("QueryName").SQL = "type the entire SQL statement
> > here"
> >
> > note that you have to set the SQL property of the QueryDef to a complete
> > SQL
> > statement - you can't just change "bits and pieces" of it.
> >
> > hth
> >
> >
> > "thread" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Hi all,
> >> I'm trying to find a way to change the sentece of the sql inside the
> >> query via vba code
> >> for now no clue
> >>

> >
> >

>
>



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      17th Dec 2006
No point getting into an endless semantic argument, but if you consistently
use the same field names, it's certainly conceivable that you might have the
following SQL statements where it doesn't make sense for Table1 and Table2
to be the same table:

UPDATE Table1 SET ConfirmationDate = Date() WHERE ConfirmedFG = True

UPDATE Table2 SET ConfirmationDate = Date() WHERE ConfirmedFG = True

Heck, you could even be talking about

SELECT * FROM Table1

SELECT * FROM Table2

<grin>


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"tina" <(E-Mail Removed)> wrote in message
news:O9ehh.513536$(E-Mail Removed)...
> <pickier>
>
> but if you can run the same SQL statement on two different tables by
> changing only the table name, they must be identical but for the table
> name.
> sounds to me like that should be one table, with a field to hold whatever
> data is currently stored in the table name...
>
>
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
> news:(E-Mail Removed)...
>> <picky>
>>
>> CurrentDb.QueryDefs("QueryName").SQL = _
>> Replace(CurrentDb.QueryDefs("QueryName").SQL, "Table1", "Table2")
>>
>> or, more efficiently,
>>
>> Dim qdfCurr As DAO.QueryDef
>>
>> Set qdfCurr = CurrentDb.QueryDefs("QueryName")
>> qdfCurr.SQL = Replace(qdfCurr.SQL, "Table1", "Table2")
>> </picky>
>>
>>
>>
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no private e-mails, please)
>>
>>
>> "tina" <(E-Mail Removed)> wrote in message
>> news:Sa9hh.221344$(E-Mail Removed)...
>> > try
>> >
>> > CurrentDb.QueryDefs("QueryName").SQL = "type the entire SQL
>> > statement
>> > here"
>> >
>> > note that you have to set the SQL property of the QueryDef to a
>> > complete
>> > SQL
>> > statement - you can't just change "bits and pieces" of it.
>> >
>> > hth
>> >
>> >
>> > "thread" <(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> Hi all,
>> >> I'm trying to find a way to change the sentece of the sql inside the
>> >> query via vba code
>> >> for now no clue
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
thread
Guest
Posts: n/a
 
      18th Dec 2006
what i found that was best for me is the issue that i can programmicly
pick up diffrent fields and add them to the recordsource of the form so
that way i just had to make some kind of dynamic arguments for the
textboxes that are there and have diffrent grouping for the same
modular form.
it can save alot of space
Douglas J. Steele лъб:
> No point getting into an endless semantic argument, but if you consistently
> use the same field names, it's certainly conceivable that you might have the
> following SQL statements where it doesn't make sense for Table1 and Table2
> to be the same table:
>
> UPDATE Table1 SET ConfirmationDate = Date() WHERE ConfirmedFG = True
>
> UPDATE Table2 SET ConfirmationDate = Date() WHERE ConfirmedFG = True
>
> Heck, you could even be talking about
>
> SELECT * FROM Table1
>
> SELECT * FROM Table2
>
> <grin>
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "tina" <(E-Mail Removed)> wrote in message
> news:O9ehh.513536$(E-Mail Removed)...
> > <pickier>
> >
> > but if you can run the same SQL statement on two different tables by
> > changing only the table name, they must be identical but for the table
> > name.
> > sounds to me like that should be one table, with a field to hold whatever
> > data is currently stored in the table name...
> >
> >
> > "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
> > news:(E-Mail Removed)...
> >> <picky>
> >>
> >> CurrentDb.QueryDefs("QueryName").SQL = _
> >> Replace(CurrentDb.QueryDefs("QueryName").SQL, "Table1", "Table2")
> >>
> >> or, more efficiently,
> >>
> >> Dim qdfCurr As DAO.QueryDef
> >>
> >> Set qdfCurr = CurrentDb.QueryDefs("QueryName")
> >> qdfCurr.SQL = Replace(qdfCurr.SQL, "Table1", "Table2")
> >> </picky>
> >>
> >>
> >>
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no private e-mails, please)
> >>
> >>
> >> "tina" <(E-Mail Removed)> wrote in message
> >> news:Sa9hh.221344$(E-Mail Removed)...
> >> > try
> >> >
> >> > CurrentDb.QueryDefs("QueryName").SQL = "type the entire SQL
> >> > statement
> >> > here"
> >> >
> >> > note that you have to set the SQL property of the QueryDef to a
> >> > complete
> >> > SQL
> >> > statement - you can't just change "bits and pieces" of it.
> >> >
> >> > hth
> >> >
> >> >
> >> > "thread" <(E-Mail Removed)> wrote in message
> >> > news:(E-Mail Removed)...
> >> >> Hi all,
> >> >> I'm trying to find a way to change the sentece of the sql inside the
> >> >> query via vba code
> >> >> for now no clue
> >> >>
> >> >
> >> >
> >>
> >>

> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
extract SQL sentence from a query via vba code thread Microsoft Access 1 24th May 2007 08:49 AM
Changing Query Property with code =?Utf-8?B?S2VuIFZhbGVudGk=?= Microsoft Access Macros 0 1st Dec 2005 06:39 PM
Changing UPPERCASE to Sentence Case Roger Bell Microsoft Access 5 19th Nov 2004 04:21 PM
Changing a query properties in code John Acocella Microsoft Access VBA Modules 12 24th Mar 2004 03:46 AM
Re: Changing to sentence case using VBA Ron de Bruin Microsoft Excel Worksheet Functions 4 27th Aug 2003 01:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:22 AM.