473,406 Members | 2,390 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,406 software developers and data experts.

How to specify mdb as datasource?

I want to connect to another mdb from an existing mbd - very simple. (same
local disk, same version)

when I use this convention:

Dim wrkJet As DAO.Workspace
Dim db as DAO.Database
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(c:\database\my.mbd, True)

it works great. I've discovered if I use this convention:

Set db = wrkJet.OpenDatabase(varV, True)

I get a "Select Data Source" window in which I can browse for a data
source - this is *great*, but I can't seem to figure out how to use this
feature. If I browse to and select "c:\database\my.mbd" and click ok, it
creates something called "my.mdb.dsn" that doesn't seem to do anything. Is
this a syntax issue? How can I use the "Select Data Source" window to
connect to another mdb?

Here is more complete code:

Public Sub Maintenance
Dim db, dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim varV As Variant
Dim wrkJet As DAO.Workspace
Set dbs = CurrentDb
dbs.TableDefs.Refresh
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(varV, True) <<== Here is where I get
"Select Data Source" window
[code omitted]
End Sub
Nov 12 '05 #1
4 4944
"deko" <dj****@hotmail.com> wrote in message news:<eN*****************@newssvr27.news.prodigy.c om>...
I want to connect to another mdb from an existing mbd - very simple. (same
local disk, same version)

when I use this convention:

Dim wrkJet As DAO.Workspace
Dim db as DAO.Database
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(c:\database\my.mbd, True)

it works great. I've discovered if I use this convention:

Set db = wrkJet.OpenDatabase(varV, True)

I get a "Select Data Source" window in which I can browse for a data
source - this is *great*, but I can't seem to figure out how to use this
feature. If I browse to and select "c:\database\my.mbd" and click ok, it
creates something called "my.mdb.dsn" that doesn't seem to do anything. Is
this a syntax issue? How can I use the "Select Data Source" window to
connect to another mdb?

Here is more complete code:

Public Sub Maintenance
Dim db, dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim varV As Variant
Dim wrkJet As DAO.Workspace
Set dbs = CurrentDb
dbs.TableDefs.Refresh
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(varV, True) <<== Here is where I get
"Select Data Source" window
[code omitted]
End Sub

If you read the code, varV never has a value. If you want the user to
be able to browse for a file and assign it to that variable, then
you'd have to do a couple of things:
1. store the variable value in a table or custom database property
2. prompt the user to look for the file. (There's some really handy
code to do this here...
http://www.mvps.org/access/api/api0001.htm

You'd just assign the return value to a string, and then store it
somewhere. Okay, so how do you know the record exists? You query the
table it should be in, and if the recordcount=0 or the open fails,
then you prompt the user to find the file for you...

HTH,
Pieter
Nov 12 '05 #2
Hi and thanks for the reply.

I understand that varV is missing - Windows figures this out and thus asks
for the missing Data Source in the "Select Data Source" dialog. I should be
able to use that dialog to get the right datasource. I've never used this
dialog before, and I'm not use what syntax to use, or what parameters are
required, or what constraints exist. While I could write code to get varV
(using the Common Dialog), I would much rather use the built-in "Select Data
Source" dialog - so my question is really about using that dialog and
understanding how Access recognizes and connects to different DSNs. For
example: How do I specify an Access mdb as a DSN name? What's the
difference between a File Data Source and a Machine Data Source?

Sorry if I wasn't clear in my first post....
Nov 12 '05 #3
Hi Deko,

You can't link in another mdb file using ODBC (at least in 97)

What the various DSN's are, are explained in the 'select DSN' dialog.

Machine dsns
user dsn - local to machine only user can use
system dsn - local, all users can use, as well as remote services.

file dsn
creates a .dsn file to use

As someone else said in the thread - the best way is to use the code
from the access web to get the user to locate the mdb file, loop
through the linked tables and set the .connect and then .refreshlink

Peter

"deko" <dj****@hotmail.com> wrote in message news:<%b****************@newssvr29.news.prodigy.co m>...
Hi and thanks for the reply.

I understand that varV is missing - Windows figures this out and thus asks
for the missing Data Source in the "Select Data Source" dialog. I should be
able to use that dialog to get the right datasource. I've never used this
dialog before, and I'm not use what syntax to use, or what parameters are
required, or what constraints exist. While I could write code to get varV
(using the Common Dialog), I would much rather use the built-in "Select Data
Source" dialog - so my question is really about using that dialog and
understanding how Access recognizes and connects to different DSNs. For
example: How do I specify an Access mdb as a DSN name? What's the
difference between a File Data Source and a Machine Data Source?

Sorry if I wasn't clear in my first post....

Nov 12 '05 #4
> You can't link in another mdb file using ODBC (at least in 97)

10-4

I did look at that code on the Access web - I think that may contain more
functionality than I need...

I've been using this:

Private Sub FindMdb() 'requires reference to Microsoft Office 11.0 Object
Library
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.Title = " Select Access Database"
.Filters.Clear
.Filters.Add "Microsoft Office Access Databases", "*.mdb"
End With
If fDialog.Show = True Then
For Each varFile In fDialog.SelectedItems
If Len(varFile) > 0 Then
varV = varFile
Else
Exit Sub
End If
Next
End If
End Sub

Thanks again for the help!
Nov 12 '05 #5

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

Similar topics

13
by: DraguVaso | last post by:
Hi, I need a function that gives me the number of Columns shown in a DataGrid. So I don't need to know the number of columns shown in tha DataSource, because this number can be completely...
3
by: Alvaro E. Gonzalez V. | last post by:
Hello!!! I'm building a control that in a property assign a Dataset which they are initialized and another property Like DataMember. Similar as it happens to the DataSource property of a...
1
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But it always use the web form's name as the default...
4
by: dyw55a | last post by:
Donna Mar 15, 10:11 am show options Newsgroups: microsoft.public.dotnet.framework.adonet From: "Donna" <dyw...@yahoo.com> - Find messages by this author Date: 15 Mar 2005 10:11:56 -0800...
4
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
3
by: Dabbler | last post by:
What is the best way to have a FormView page open on a specific row selected from a GridView? I'm passing the primary key in the url as in detailview.aspx?mode=edit&pk=42 I'm using an...
1
by: ad | last post by:
I use a GridView to display data , the datasource of my GridView is from a ObjectDataSource. How can I specify the sort column?
2
by: Edwin Smith | last post by:
Hello: I have a form which I would like to fill with data from one row of an ODBC database table. I have created the Table adapter and I have a query: SELECT PATIENT.Name, PATIENT.address...
0
by: MeDontGetSomething | last post by:
The thing is I'm currently working with Infragistics NetAdvantage UltraGrid and I use DataSet with one table as DataSource. Since data dosen't come straigh from database i have to make columns of...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.