473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Select data from other DB

bsn
Hello NG
I want to select data from another DB, and use this data in currentDB.
I have this SQL in a VBA procedure:
Sql = "SELECT * FROM Firma [MS Access;Database=" & strPath & strFileName &
";]"

It is not working

Any suggestions...

Thanks in advance...

Bjarne
Feb 18 '06 #1
10 12617
"bsn" <bsnsnabelaoncabledotdk> wrote in message
news:43***********************@dread12.news.tele.d k...
Hello NG
I want to select data from another DB, and use this data in currentDB.
I have this SQL in a VBA procedure:
Sql = "SELECT * FROM Firma [MS Access;Database=" & strPath & strFileName &
";]"

It is not working

Any suggestions...

Thanks in advance...

Bjarne

The syntax is not quite right, you are missing the IN ""
This format is useful if you needed to set other attributes, such as a
password, then you need to end up with something like:
SELECT * FROM MyTable IN "" [MS Access;PWD=secret;DATABASE=C:\Test.mdb]

However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.mdb"
Feb 18 '06 #2
bsn

"Anthony England" <ae******@oops.co.uk> skrev
The syntax is not quite right, you are missing the IN ""
This format is useful if you needed to set other attributes, such as a
password, then you need to end up with something like:
SELECT * FROM MyTable IN "" [MS Access;PWD=secret;DATABASE=C:\Test.mdb]

However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.mdb"

Thank you...I tried this SQL, but it is not working...

SELECT * FROM Firma IN "C:\Documents and Settings\Bjarne S.
Nielsen\Skrivebord\Wl2kdata.mdb"

Bjarne
Feb 18 '06 #3
bsn

"Anthony England" <ae******@oops.co.uk>
The syntax is not quite right, you are missing the IN ""
This format is useful if you needed to set other attributes, such as a
password, then you need to end up with something like:
SELECT * FROM MyTable IN "" [MS Access;PWD=secret;DATABASE=C:\Test.mdb]

If I try to run the sql in QBE, then it goes well, but not in my VBA code:

Sql = "SELECT * FROM Firma IN """" [MS Access;DATABASE=" & strPath &
strFileName & ";]"
RS.Open Sql
Debug.Print Rs!FirmaID

Bjarne

Feb 18 '06 #4
"bsn" <bsnsnabelaoncabledotdk> wrote in message
news:43***********************@dread12.news.tele.d k...

"Anthony England" <ae******@oops.co.uk>
The syntax is not quite right, you are missing the IN ""
This format is useful if you needed to set other attributes, such as a
password, then you need to end up with something like:
SELECT * FROM MyTable IN "" [MS Access;PWD=secret;DATABASE=C:\Test.mdb]

If I try to run the sql in QBE, then it goes well, but not in my VBA code:

Sql = "SELECT * FROM Firma IN """" [MS Access;DATABASE=" & strPath &
strFileName & ";]"
RS.Open Sql
Debug.Print Rs!FirmaID

Bjarne

Well perhaps the mistake is elsewhere in the code. Try opening a recordset
for a normal local table, does it work? I guess because you call rs.open
you are coding using the ADO object library, but in any case you need to
show a full bit of code. Here are two examples - one using DAO and the
other ADO:

Public Sub DAO_Test()

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngCount As Long

Set dbs = CurrentDb

' strSQL = "SELECT * FROM tblContacts IN ""C:\Documents and
Settings\Test.mdb"""

strSQL = "SELECT * FROM tblContacts IN """" [MS Access;" & _
"DATABASE=C:\Documents and Settings\Test.mdb]"

Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly, dbReadOnly)

While Not rst.EOF
lngCount = lngCount + 1
rst.MoveNext
Wend

MsgBox "There are " & CStr(lngCount) & " records.", vbInformation

Exit_Handler:

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Public Sub ADO_Test()

On Error GoTo Err_Handler

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim lngCount As Long

' strSQL = "SELECT * FROM tblContacts IN ""C:\Documents and
Settings\Test.mdb"""

strSQL = "SELECT * FROM tblContacts IN """" [MS Access;" & _
"DATABASE=C:\Documents and Settings\Test.mdb]"

Set rst = New ADODB.Recordset

rst.Open strSQL, CurrentProject.Connection

While Not rst.EOF
lngCount = lngCount + 1
rst.MoveNext
Wend

MsgBox "There are " & CStr(lngCount) & " records.", vbInformation

Exit_Handler:

If Not rst Is Nothing Then
If rst.State > adStateOpen Then
rst.Close
End If
Set rst = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Feb 18 '06 #5
bsn

"Anthony England" <ae******@oops.co.uk> skrev
rst.Open strSQL, CurrentProject.Connection

Works like a charme now...I forgot to set connection correct...
Thank you very much...
Bjarne
Feb 18 '06 #6
"Anthony England" <ae******@oops.co.uk> wrote in
news:dt**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.mdb"


My copies of Access use single quotes for this. Is that an
internationalization issue (I'm on US settings)?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Feb 18 '06 #7

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dt**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.mdb"


My copies of Access use single quotes for this. Is that an
internationalization issue (I'm on US settings)?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

My settings are UK, but I don't believe that matters. I think either single
or double quotes are acceptable to JET but let us know if it doesn't on your
machine.

I also tested selecting Tools>Options>Tables/Queries and choosing SQL Server
Compatible Syntax (ANSI 92) then a query like
SELECT * FROM Contact WHERE Surname LIKE "Smith*"
does not work, I have to use:
SELECT * FROM Contact WHERE Surname LIKE "Smith%"

However, with my tests so far either within saved queries or via vba, and
regardless of settings, either single or double seem to be fine
SELECT * FROM Contact WHERE Surname="Smith"
SELECT * FROM Contact WHERE Surname='Smith'

Feb 19 '06 #8
bsn

"Anthony England" <ae******@oops.co.uk> skrev
My settings are UK, but I don't believe that matters. I think either
single or double quotes are acceptable to JET but let us know if it
doesn't on your machine.

My settings are DK - both quotes acceptable to JET.
Bjarne
Feb 19 '06 #9
"Anthony England" <ae******@oops.co.uk> wrote in
news:dt**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com:
"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dt**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.mdb"


My copies of Access use single quotes for this. Is that an
internationalization issue (I'm on US settings)?


My settings are UK, but I don't believe that matters. I think
either single or double quotes are acceptable to JET but let us
know if it doesn't on your machine.

I also tested selecting Tools>Options>Tables/Queries and choosing
SQL Server Compatible Syntax (ANSI 92) then a query like
SELECT * FROM Contact WHERE Surname LIKE "Smith*"
does not work, I have to use:
SELECT * FROM Contact WHERE Surname LIKE "Smith%"

However, with my tests so far either within saved queries or via
vba, and regardless of settings, either single or double seem to
be fine SELECT * FROM Contact WHERE Surname="Smith"
SELECT * FROM Contact WHERE Surname='Smith'


When you set a source in a different MDB in the query properties
Windows, the QBE writes the SQL with a single quote, so that seems
to suggest to me that the single quote is preferred.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Feb 19 '06 #10

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dt**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com:
"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dt**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:

However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.mdb"

My copies of Access use single quotes for this. Is that an
internationalization issue (I'm on US settings)?


My settings are UK, but I don't believe that matters. I think
either single or double quotes are acceptable to JET but let us
know if it doesn't on your machine.

I also tested selecting Tools>Options>Tables/Queries and choosing
SQL Server Compatible Syntax (ANSI 92) then a query like
SELECT * FROM Contact WHERE Surname LIKE "Smith*"
does not work, I have to use:
SELECT * FROM Contact WHERE Surname LIKE "Smith%"

However, with my tests so far either within saved queries or via
vba, and regardless of settings, either single or double seem to
be fine SELECT * FROM Contact WHERE Surname="Smith"
SELECT * FROM Contact WHERE Surname='Smith'


When you set a source in a different MDB in the query properties
Windows, the QBE writes the SQL with a single quote, so that seems
to suggest to me that the single quote is preferred.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

Indeed. And here I would have no objection. But I don't always like the
way my queries are adjusted with the query editor.
Feb 19 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
2
by: Edwinah63 | last post by:
Hi Everyone, All the very best for 2004!! i need urgent help with this problem, the users are about to skin me alive!! we have an access front end with linked to sql server 2k tables. ...
4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
5
by: Allan M. | last post by:
I have a series of select boxes that must be populated client side, because they interact with each other. The design specification calls for these boxes to be updated without having to make a...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
5
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but...
1
by: robin1983 | last post by:
Hi to all, i m newer to this site and fresher in Ajax world. Actually i get a problem while accessing data from Database. I have a combo box in my pages. Actually i want to access data from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.