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

Programmatically "Connecting" & Linking to another MDB !

I have an Access Database called "TEMP"

On Opening the "TEMP" Database, I need to use VBA (programmatically):
a) to connect to another database called "PMF"
b) the PMF database requires a password on opening called "allow"
c) to link 5 Tables in the PMF Database ... Table1,2,3,4,5

How do I accomplish the above programmatically using VBA ?

Thx & Best Rgds,
Prakash.
Nov 13 '05 #1
2 5698
pr*************@gmail.com (Prakash Wadhwani) wrote in message news:<ca**************************@posting.google. com>...
I have an Access Database called "TEMP"

On Opening the "TEMP" Database, I need to use VBA (programmatically):
a) to connect to another database called "PMF"
b) the PMF database requires a password on opening called "allow"
c) to link 5 Tables in the PMF Database ... Table1,2,3,4,5

How do I accomplish the above programmatically using VBA ?

Thx & Best Rgds,
Prakash.


Straight outta Compton!!, umm I mean the help file...
The only modification you need to make is to accept a username and
password combination to the database in question, and open a workspace
with that user/pwd combination.

Open a Workspace (from the AccessXP help):
CreateWorkspace Method Example

This example uses the CreateWorkspace method to create both a
Microsoft Jet workspace and an ODBCDirect workspace. It then lists the
properties of both types of workspace.

Sub CreateWorkspaceX()

Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim wrkLoop As Workspace
Dim prpLoop As Property

' Create an ODBCDirect workspace. Until you create
' Microsoft Jet workspace, the Microsoft Jet database
' engine will not be loaded into memory.
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", _
"", dbUseODBC)
Workspaces.Append wrkODBC

DefaultType = dbUseJet
' Create an unnamed Workspace object of the type
' specified by the DefaultType property of DBEngine
' (dbUseJet).
Set wrkJet = CreateWorkspace("", "admin", "")

' Enumerate Workspaces collection.
Debug.Print "Workspace objects in Workspaces collection:"
For Each wrkLoop In Workspaces
Debug.Print " " & wrkLoop.Name
Next wrkLoop

With wrkODBC
' Enumerate Properties collection of ODBCDirect
' workspace.
Debug.Print "Properties of " & .Name
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With

With wrkJet
' Enumerate Properties collection of Microsoft Jet
' workspace.
Debug.Print _
"Properties of unnamed Microsoft Jet workspace"
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With

wrkODBC.Close
wrkJet.Close

End Sub

Sub ConnectOutput(dbsTemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)

Dim tdfLinked As TableDef
Dim rstLinked As Recordset
Dim intTemp As Integer

' Create a new TableDef, set its Connect and
' SourceTableName properties based on the passed
' arguments, and append it to the TableDefs collection.
Set tdfLinked = dbsTemp.CreateTableDef(strTable)

tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked

Set rstLinked = dbsTemp.OpenRecordset(strTable)

Debug.Print "Data from linked table:"

' Display the first three records of the linked table.
intTemp = 1
With rstLinked
Do While Not .EOF And intTemp <= 3
Debug.Print , .Fields(0), .Fields(1)
intTemp = intTemp + 1
.MoveNext
Loop
If Not .EOF Then Debug.Print , "[additional records]"
.Close
End With

' Delete the linked table because this is a demonstration.
dbsTemp.TableDefs.Delete strTable

End Sub
Help is your FRIEND. Read. Learn. Be more productive.
Nov 13 '05 #2
Thx Peter ! I did chk the help file before posting. I typed "LINKED"
.... nothing came up in the VBA help window. On typing "Connect", I did
get quite a bit but most of it pertained to an SQL database.

My VBA skills are just average and the code there just seemed so
daunting. So I was looking for some ready-made "working" code which I
could probably just slip into my app replacing just the database &
table names.

Thank you very much for your help. Much appreciated.

Best Rgds,
Prakash.


pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
pr*************@gmail.com (Prakash Wadhwani) wrote in message news:<ca**************************@posting.google. com>...
I have an Access Database called "TEMP"

On Opening the "TEMP" Database, I need to use VBA (programmatically):
a) to connect to another database called "PMF"
b) the PMF database requires a password on opening called "allow"
c) to link 5 Tables in the PMF Database ... Table1,2,3,4,5

How do I accomplish the above programmatically using VBA ?

Thx & Best Rgds,
Prakash.


Straight outta Compton!!, umm I mean the help file...
The only modification you need to make is to accept a username and
password combination to the database in question, and open a workspace
with that user/pwd combination.

Open a Workspace (from the AccessXP help):
CreateWorkspace Method Example

This example uses the CreateWorkspace method to create both a
Microsoft Jet workspace and an ODBCDirect workspace. It then lists the
properties of both types of workspace.

Sub CreateWorkspaceX()

Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim wrkLoop As Workspace
Dim prpLoop As Property

' Create an ODBCDirect workspace. Until you create
' Microsoft Jet workspace, the Microsoft Jet database
' engine will not be loaded into memory.
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", _
"", dbUseODBC)
Workspaces.Append wrkODBC

DefaultType = dbUseJet
' Create an unnamed Workspace object of the type
' specified by the DefaultType property of DBEngine
' (dbUseJet).
Set wrkJet = CreateWorkspace("", "admin", "")

' Enumerate Workspaces collection.
Debug.Print "Workspace objects in Workspaces collection:"
For Each wrkLoop In Workspaces
Debug.Print " " & wrkLoop.Name
Next wrkLoop

With wrkODBC
' Enumerate Properties collection of ODBCDirect
' workspace.
Debug.Print "Properties of " & .Name
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With

With wrkJet
' Enumerate Properties collection of Microsoft Jet
' workspace.
Debug.Print _
"Properties of unnamed Microsoft Jet workspace"
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & prpLoop
Next prpLoop
On Error GoTo 0
End With

wrkODBC.Close
wrkJet.Close

End Sub

Sub ConnectOutput(dbsTemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)

Dim tdfLinked As TableDef
Dim rstLinked As Recordset
Dim intTemp As Integer

' Create a new TableDef, set its Connect and
' SourceTableName properties based on the passed
' arguments, and append it to the TableDefs collection.
Set tdfLinked = dbsTemp.CreateTableDef(strTable)

tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked

Set rstLinked = dbsTemp.OpenRecordset(strTable)

Debug.Print "Data from linked table:"

' Display the first three records of the linked table.
intTemp = 1
With rstLinked
Do While Not .EOF And intTemp <= 3
Debug.Print , .Fields(0), .Fields(1)
intTemp = intTemp + 1
.MoveNext
Loop
If Not .EOF Then Debug.Print , "[additional records]"
.Close
End With

' Delete the linked table because this is a demonstration.
dbsTemp.TableDefs.Delete strTable

End Sub
Help is your FRIEND. Read. Learn. Be more productive.

Nov 13 '05 #3

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

Similar topics

4
by: Klemens | last post by:
One database tells on every connect statement: SQL1092N "" does not have the authority to perform the requested command. Another database at the same instance works fine. One day before the...
1
by: jj | last post by:
Hi NG I got 2 tables In both of the tables there are 4 indentical fields 1) Road name 2) House number 3) Letter 4) Floor In table one there is an extra field - an Id field. In this table...
0
by: Winterminute | last post by:
I am trying to read a list of install programs using WMI with ASP.NET/C#. However, it fails with "Invalid Class". I have confirmed that if I query LOCALHOST then it works fine, but if I query a...
4
by: Logan | last post by:
I am interested in programmatically connecting my computer to my cell phone's bluetooth Hands-Free Profile (HFP). So can can use my computer to answer and make calls as well as route the audio...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
by: gujarsachin2001 | last post by:
hello friends i m connecting to http or https url programatically through console application using follwoing methods of credentilas but if there is username & password for that url through this...
3
by: eholz1 | last post by:
Hello PHP programmers. I had a brilliant idea on one of my pages that selects some data from my mysql database. I first set the page up to display some info and an image, just one item, with a...
25
by: bubbles | last post by:
Using Access 2003 front-end, with SQL Server 2005 backend. I need to make the front-end application automatically refresh the linked SQL Server tables. New tables will be added dynamically in...
3
by: BobRoyAce | last post by:
I am using Visual Studio 2008 w/ VB.NET. For the database, I am using SQL Server 2005, which is running on a dedicated server box. I am creating a WinForms application for a client. It is run...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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,...
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.