PC Review


Reply
Thread Tools Rate Thread

access selective data...using query

 
 
Hemant_india
Guest
Posts: n/a
 
      7th Nov 2008
hi
below is macro i have recorded
when i put .commandtext=qrystring i get error
can somebody help me?
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 07/11/2008 by kjsb
'
Dim qrystring
qrystring = "select * from kjsb.d010009 where lbrcode=5"
'
With ActiveSheet.QueryTables.Add(Connection:= _
"OLEDB;Provider=MSDAORA.1;User ID=test;Data Source=kjsb",
Destination:=Range( _
"A1"))
.CommandType = xlCmdTable
.CommandText = Array("""KJSB"".""D010009""")
'.CommandText = qrystring
.Name = "kjsb (Default) D010009"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = _
"C:\Documents and Settings\kjsb1\My Documents\My Data Sources\kjsb
(Default) D010009.odc"
.Refresh BackgroundQuery:=False
End With
End Sub

--
hemu
 
Reply With Quote
 
 
 
 
Member
Join Date: Apr 2008
Posts: 66
 
      7th Nov 2008
Hi,
Your problem is that with a query of command type Table (xlCmdTable), you need to supply the table name only in the command text, so qrystring = "kjsb.d010009" would work fine. If you want to use SQL then you need to change the command type to xlCmdSql.
HTH,
Paul
 
Reply With Quote
 
Alan Moseley
Guest
Posts: n/a
 
      7th Nov 2008
Without knowing the error message I am struggling a little, but I would think
that your CommandType should be set to xlCmdSQL and NOT xlCmdTable

--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Hemant_india" wrote:

> hi
> below is macro i have recorded
> when i put .commandtext=qrystring i get error
> can somebody help me?
> Sub Macro1()
> '
> ' Macro1 Macro
> ' Macro recorded 07/11/2008 by kjsb
> '
> Dim qrystring
> qrystring = "select * from kjsb.d010009 where lbrcode=5"
> '
> With ActiveSheet.QueryTables.Add(Connection:= _
> "OLEDB;Provider=MSDAORA.1;User ID=test;Data Source=kjsb",
> Destination:=Range( _
> "A1"))
> .CommandType = xlCmdTable
> .CommandText = Array("""KJSB"".""D010009""")
> '.CommandText = qrystring
> .Name = "kjsb (Default) D010009"
> .FieldNames = True
> .RowNumbers = False
> .FillAdjacentFormulas = False
> .PreserveFormatting = True
> .RefreshOnFileOpen = False
> .BackgroundQuery = True
> .RefreshStyle = xlInsertDeleteCells
> .SavePassword = False
> .SaveData = True
> .AdjustColumnWidth = True
> .RefreshPeriod = 0
> .PreserveColumnInfo = True
> .SourceConnectionFile = _
> "C:\Documents and Settings\kjsb1\My Documents\My Data Sources\kjsb
> (Default) D010009.odc"
> .Refresh BackgroundQuery:=False
> End With
> End Sub
>
> --
> hemu

 
Reply With Quote
 
Hemant_india
Guest
Posts: n/a
 
      7th Nov 2008
eroor is table not found
however if run the code as it is it works
--
hemu


"Alan Moseley" wrote:

> Without knowing the error message I am struggling a little, but I would think
> that your CommandType should be set to xlCmdSQL and NOT xlCmdTable
>
> --
> Alan Moseley IT Consultancy
> http://www.amitc.co.uk
>
> If I have solved your problem, please click Yes below. Thanks.
>
>
> "Hemant_india" wrote:
>
> > hi
> > below is macro i have recorded
> > when i put .commandtext=qrystring i get error
> > can somebody help me?
> > Sub Macro1()
> > '
> > ' Macro1 Macro
> > ' Macro recorded 07/11/2008 by kjsb
> > '
> > Dim qrystring
> > qrystring = "select * from kjsb.d010009 where lbrcode=5"
> > '
> > With ActiveSheet.QueryTables.Add(Connection:= _
> > "OLEDB;Provider=MSDAORA.1;User ID=test;Data Source=kjsb",
> > Destination:=Range( _
> > "A1"))
> > .CommandType = xlCmdTable
> > .CommandText = Array("""KJSB"".""D010009""")
> > '.CommandText = qrystring
> > .Name = "kjsb (Default) D010009"
> > .FieldNames = True
> > .RowNumbers = False
> > .FillAdjacentFormulas = False
> > .PreserveFormatting = True
> > .RefreshOnFileOpen = False
> > .BackgroundQuery = True
> > .RefreshStyle = xlInsertDeleteCells
> > .SavePassword = False
> > .SaveData = True
> > .AdjustColumnWidth = True
> > .RefreshPeriod = 0
> > .PreserveColumnInfo = True
> > .SourceConnectionFile = _
> > "C:\Documents and Settings\kjsb1\My Documents\My Data Sources\kjsb
> > (Default) D010009.odc"
> > .Refresh BackgroundQuery:=False
> > End With
> > End Sub
> >
> > --
> > hemu

 
Reply With Quote
 
Alan Moseley
Guest
Posts: n/a
 
      7th Nov 2008
Your command text is 'SELECT * FROM .....etc', and your CommandType is
xlCmdTable. You do not have a table called 'SELECT * FROM ....etc'. Change
your commandtype to xlCmdSQL.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.


"Hemant_india" wrote:

> eroor is table not found
> however if run the code as it is it works
> --
> hemu
>
>
> "Alan Moseley" wrote:
>
> > Without knowing the error message I am struggling a little, but I would think
> > that your CommandType should be set to xlCmdSQL and NOT xlCmdTable
> >
> > --
> > Alan Moseley IT Consultancy
> > http://www.amitc.co.uk
> >
> > If I have solved your problem, please click Yes below. Thanks.
> >
> >
> > "Hemant_india" wrote:
> >
> > > hi
> > > below is macro i have recorded
> > > when i put .commandtext=qrystring i get error
> > > can somebody help me?
> > > Sub Macro1()
> > > '
> > > ' Macro1 Macro
> > > ' Macro recorded 07/11/2008 by kjsb
> > > '
> > > Dim qrystring
> > > qrystring = "select * from kjsb.d010009 where lbrcode=5"
> > > '
> > > With ActiveSheet.QueryTables.Add(Connection:= _
> > > "OLEDB;Provider=MSDAORA.1;User ID=test;Data Source=kjsb",
> > > Destination:=Range( _
> > > "A1"))
> > > .CommandType = xlCmdTable
> > > .CommandText = Array("""KJSB"".""D010009""")
> > > '.CommandText = qrystring
> > > .Name = "kjsb (Default) D010009"
> > > .FieldNames = True
> > > .RowNumbers = False
> > > .FillAdjacentFormulas = False
> > > .PreserveFormatting = True
> > > .RefreshOnFileOpen = False
> > > .BackgroundQuery = True
> > > .RefreshStyle = xlInsertDeleteCells
> > > .SavePassword = False
> > > .SaveData = True
> > > .AdjustColumnWidth = True
> > > .RefreshPeriod = 0
> > > .PreserveColumnInfo = True
> > > .SourceConnectionFile = _
> > > "C:\Documents and Settings\kjsb1\My Documents\My Data Sources\kjsb
> > > (Default) D010009.odc"
> > > .Refresh BackgroundQuery:=False
> > > End With
> > > End Sub
> > >
> > > --
> > > hemu

 
Reply With Quote
 
Hemant_india
Guest
Posts: n/a
 
      7th Nov 2008
ok
but if i keep commandtype as xlCmdTable and use syntax as
..commandtext=array(my sqlstring) ... then it should run ... i guess
i think i am missing something while writing the query
here i am accessing the table from oracle
--
hemu


"Alan Moseley" wrote:

> Your command text is 'SELECT * FROM .....etc', and your CommandType is
> xlCmdTable. You do not have a table called 'SELECT * FROM ....etc'. Change
> your commandtype to xlCmdSQL.
> --
> Alan Moseley IT Consultancy
> http://www.amitc.co.uk
>
> If I have solved your problem, please click Yes below. Thanks.
>
>
> "Hemant_india" wrote:
>
> > eroor is table not found
> > however if run the code as it is it works
> > --
> > hemu
> >
> >
> > "Alan Moseley" wrote:
> >
> > > Without knowing the error message I am struggling a little, but I would think
> > > that your CommandType should be set to xlCmdSQL and NOT xlCmdTable
> > >
> > > --
> > > Alan Moseley IT Consultancy
> > > http://www.amitc.co.uk
> > >
> > > If I have solved your problem, please click Yes below. Thanks.
> > >
> > >
> > > "Hemant_india" wrote:
> > >
> > > > hi
> > > > below is macro i have recorded
> > > > when i put .commandtext=qrystring i get error
> > > > can somebody help me?
> > > > Sub Macro1()
> > > > '
> > > > ' Macro1 Macro
> > > > ' Macro recorded 07/11/2008 by kjsb
> > > > '
> > > > Dim qrystring
> > > > qrystring = "select * from kjsb.d010009 where lbrcode=5"
> > > > '
> > > > With ActiveSheet.QueryTables.Add(Connection:= _
> > > > "OLEDB;Provider=MSDAORA.1;User ID=test;Data Source=kjsb",
> > > > Destination:=Range( _
> > > > "A1"))
> > > > .CommandType = xlCmdTable
> > > > .CommandText = Array("""KJSB"".""D010009""")
> > > > '.CommandText = qrystring
> > > > .Name = "kjsb (Default) D010009"
> > > > .FieldNames = True
> > > > .RowNumbers = False
> > > > .FillAdjacentFormulas = False
> > > > .PreserveFormatting = True
> > > > .RefreshOnFileOpen = False
> > > > .BackgroundQuery = True
> > > > .RefreshStyle = xlInsertDeleteCells
> > > > .SavePassword = False
> > > > .SaveData = True
> > > > .AdjustColumnWidth = True
> > > > .RefreshPeriod = 0
> > > > .PreserveColumnInfo = True
> > > > .SourceConnectionFile = _
> > > > "C:\Documents and Settings\kjsb1\My Documents\My Data Sources\kjsb
> > > > (Default) D010009.odc"
> > > > .Refresh BackgroundQuery:=False
> > > > End With
> > > > End Sub
> > > >
> > > > --
> > > > hemu

 
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
Generate selective query results RoBo Microsoft Access Queries 2 22nd Feb 2008 12:13 PM
Selective Update Query =?Utf-8?B?Tm92aWNlMjAwMA==?= Microsoft Access Queries 2 31st Oct 2006 06:18 PM
selective update query =?Utf-8?B?V2FkZHk=?= Microsoft Access Getting Started 1 3rd Jun 2006 01:43 PM
Creating a Selective Query with a list box? Sapper Microsoft Access Queries 6 21st Nov 2005 10:37 PM
how do i create a selective query in access? =?Utf-8?B?amF5?= Microsoft Access Queries 1 1st Mar 2005 04:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:32 PM.