dbTalk Databases Forums  

Trouble with QueryDef object

comp.databases.ms-access comp.databases.ms-access


Discuss Trouble with QueryDef object in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rick Brandt
 
Posts: n/a

Default Re: Trouble with QueryDef object - 05-11-2010 , 01:26 AM






Nick 'The Database Guy' wrote:

Quote:
Hello everybody,

I am trying to execute the following code.

Dim qdf As QueryDef
Set qdf = New QueryDef
With qdf
.ReturnsRecords = False
.sql = CurrentDb.QueryDefs("qryLowValueMakeTable").sql
.Connect = "ODBC;DRIVER={SQL
Server};SERVER=MyServer;DATABASE=MyDB;UID=MyUserID ;PWD=MyPassword"
.Execute
.Close
End With

The code is falling over when it gets to the .Execute statement. In
the sql there are some VBA expressions, but it executes perfectly from
a DoCmd.RunSQL statement, however you must know the password and I
would rather that my users were not aware of such information. The
error I get is 3420, Object invalid or no longer set.

Any help on this would be appreciated.
Queries written in Access-SQL will seldom run on a SQL Server. You have to
use SQL Server syntax (which will definitely NOT contain any VBA).

Reply With Quote
  #2  
Old   
Nick 'The Database Guy'
 
Posts: n/a

Default Trouble with QueryDef object - 05-11-2010 , 05:09 AM






Hello everybody,

I am trying to execute the following code.

Dim qdf As QueryDef
Set qdf = New QueryDef
With qdf
.ReturnsRecords = False
.sql = CurrentDb.QueryDefs("qryLowValueMakeTable").sql
.Connect = "ODBC;DRIVER={SQL
Server};SERVER=MyServer;DATABASE=MyDB;UID=MyUserID ;PWD=MyPassword"
.Execute
.Close
End With

The code is falling over when it gets to the .Execute statement. In
the sql there are some VBA expressions, but it executes perfectly from
a DoCmd.RunSQL statement, however you must know the password and I
would rather that my users were not aware of such information. The
error I get is 3420, Object invalid or no longer set.

Any help on this would be appreciated.

Nick

Reply With Quote
  #3  
Old   
Nick 'The Database Guy'
 
Posts: n/a

Default Re: Trouble with QueryDef object - 05-11-2010 , 07:25 AM



On May 11, 7:26*am, Rick Brandt <rickbran... (AT) hotmail (DOT) com> wrote:
Quote:
Nick 'The Database Guy' wrote:





Hello everybody,

I am trying to execute the following code.

Dim qdf As QueryDef
Set qdf = New QueryDef
With qdf
* * .ReturnsRecords = False
* * .sql = CurrentDb.QueryDefs("qryLowValueMakeTable").sql
* * .Connect = "ODBC;DRIVER={SQL
Server};SERVER=MyServer;DATABASE=MyDB;UID=MyUserID ;PWD=MyPassword"
* * .Execute
* * .Close
End With

The code is falling over when it gets to the .Execute statement. *In
the sql there are some VBA expressions, but it executes perfectly from
a DoCmd.RunSQL statement, however you must know the password and I
would rather that my users were not aware of such information. *The
error I get is 3420, Object invalid or no longer set.

Any help on this would be appreciated.

Queries written in Access-SQL will seldom run on a SQL Server. *You have to
use SQL Server syntax (which will definitely NOT contain any VBA).- Hide quoted text -

- Show quoted text -
I was unsure whether it would execute on the server or the local PC so
thanks for clearing that up Rick.

Reply With Quote
  #4  
Old   
Nick 'The Database Guy'
 
Posts: n/a

Default Re: Trouble with QueryDef object - 05-11-2010 , 10:16 AM



On May 11, 1:25*pm, "Nick 'The Database Guy'" <nick... (AT) btinternet (DOT) com>
wrote:
Quote:
On May 11, 7:26*am, Rick Brandt <rickbran... (AT) hotmail (DOT) com> wrote:





Nick 'The Database Guy' wrote:

Hello everybody,

I am trying to execute the following code.

Dim qdf As QueryDef
Set qdf = New QueryDef
With qdf
* * .ReturnsRecords = False
* * .sql = CurrentDb.QueryDefs("qryLowValueMakeTable").sql
* * .Connect = "ODBC;DRIVER={SQL
Server};SERVER=MyServer;DATABASE=MyDB;UID=MyUserID ;PWD=MyPassword"
* * .Execute
* * .Close
End With

The code is falling over when it gets to the .Execute statement. *In
the sql there are some VBA expressions, but it executes perfectly from
a DoCmd.RunSQL statement, however you must know the password and I
would rather that my users were not aware of such information. *The
error I get is 3420, Object invalid or no longer set.

Any help on this would be appreciated.

Queries written in Access-SQL will seldom run on a SQL Server. *You have to
use SQL Server syntax (which will definitely NOT contain any VBA).- Hide quoted text -

- Show quoted text -

I was unsure whether it would execute on the server or the local PC so
thanks for clearing that up Rick.- Hide quoted text -

- Show quoted text -
Futher more it was a make table query and I really don't want it
generating tables on the server. All that I am looking for is a way
to bypass the request for a password, but I am not sure if this is
possible. If anyone has any hints or tips they would be gratefully
received.

Thanks,

Nick

Reply With Quote
  #5  
Old   
Rick Brandt
 
Posts: n/a

Default Re: Trouble with QueryDef object - 05-11-2010 , 01:00 PM



Nick 'The Database Guy' wrote:
Quote:
Futher more it was a make table query and I really don't want it
generating tables on the server. All that I am looking for is a way
to bypass the request for a password, but I am not sure if this is
possible. If anyone has any hints or tips they would be gratefully
received.
Then just make it a basic SELECT statement in the sql that you set. If some
of the processing requires VBA then you can always make the passthrough be
very simple and then use that as the input to a regular Access query where
you CAN use VBA.

Of course your SQL server could use trusted connections if you have a domain
and then the user would not need to provide credentials.

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.