473,699 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12675
"bsn" <bsnsnabelaonca bledotdk> wrote in message
news:43******** *************** @dread12.news.t ele.dk...
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=secr et;DATABASE=C:\ Test.mdb]

However, if not, you could also use a simpler form:
SELECT * FROM MyTable IN "C:\Test.md b"
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=secr et;DATABASE=C:\ Test.mdb]

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

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

SELECT * FROM Firma IN "C:\Documen ts and Settings\Bjarne S.
Nielsen\Skriveb ord\Wl2kdata.md b"

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=secr et;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" <bsnsnabelaonca bledotdk> wrote in message
news:43******** *************** @dread12.news.t ele.dk...

"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=secr et;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:\Docume nts and
Settings\Test.m db"""

strSQL = "SELECT * FROM tblContacts IN """" [MS Access;" & _
"DATABASE=C:\Do cuments and Settings\Test.m db]"

Set rst = dbs.OpenRecords et(strSQL, dbOpenForwardOn ly, 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.Connectio n
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim lngCount As Long

' strSQL = "SELECT * FROM tblContacts IN ""C:\Docume nts and
Settings\Test.m db"""

strSQL = "SELECT * FROM tblContacts IN """" [MS Access;" & _
"DATABASE=C:\Do cuments and Settings\Test.m db]"

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.md b"


My copies of Access use single quotes for this. Is that an
internationaliz ation 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*******@dfen ton.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.md b"


My copies of Access use single quotes for this. Is that an
internationaliz ation 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>T ables/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*******@dfen ton.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.md b"


My copies of Access use single quotes for this. Is that an
internationaliz ation 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>T ables/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

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

Similar topics

7
3516
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 in a list box and submits the form the value is put into a session variable and the relevant page is displayed (in accordance to one of the list boxes). The page is then displayed with the relevant SQL data. So far i have got the
2
6380
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. when a user tries to insert a record into one of the tables it
4
2859
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 that links to a transaction items table that links to the products table: (User Table) UserID Other user data
17
5016
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 cust_no, ded_type_cd, chk_no)
3
6466
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
5
2135
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 roundtrip to the server. The codebehind seems to be unaware of select box members populated via javascript. So, I'm having to create my own state management solution, (i.e. rewriting the VIEWSTATE mechanism) to persist the state of these select...
6
13005
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 is not an ASP.NET related question, but I know this group is knowledgeable and quick with responses. Thanks
6
4843
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 SalesManName AT Alan Time
5
2592
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 I can probably code what I want to do the hard way. I've searching around online but can't find an answer to this specific question. Here's the situation: I have a dataset table with 3 fields: one indexed as a primary key and the other two...
1
1864
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 database and put in a form variable as soon as when i select the name in the combo box. For more details i m giving the code below.. this is my first pages: empAttedence.php <table width="100%" cellpadding="2" cellspacing="1"> <form...
0
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7755
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.