Updating work mdb with test mdb objects

bulrush

Registered User.
Local time
Today, 13:34
Joined
Sep 1, 2009
Messages
209
Access 2003 on Win XP

I have a test MDB file where I do all my work. When my changes are done, I want to copy the changed objects (forms, queries, reports, modules, etc) to the "work" MDB file.

My current code from Access95/97 is not working. It seems to want an Access username and password. But I would like a way to transfer these objects without setting up Access security. We have problems/bugs with A2003 and MDB files on a network drive, and I want to avoid all those headaches.

How can I transfer an Access object from my MDB on a C: drive to an MDB on my network drive (mapped as a drive letter)?

Below is a picture of my current screen.
UTLupdatever.jpg


I click the Forms, Queries, or Reports button to get a list of that object. The list appears in the left hand list box. When I double click the item in the left list box, it gets transferred to the new MDB file and put in the right list box.

The 2 text boxes above show the current MDB file and the destination MDB file. Filenames erased for privacy.

My problem is, in my current routine (I got it from the internet), it uses an ObjectExists routine, which opens the destination MDB and requires an Access username and password. Here is the first part of the code in ObjectExists:
Code:
 Function ObjectExists(ObjectType$, ObjectName$, Optional MyDBName As String) As Integer
' Returns TRUE (-1) if an object exists in the current DB. Otherwise
' returns FALSE (0).
' Object type: can be Tables, Queries, Forms, Modules, Reports, Macros
' Object name: Name of object to look for.
' DBName: name of MDB file to check.

'On Error Resume Next
On Error GoTo MyError

Dim Found_Object%, Find_Object As String, ObjectNum As Integer
Dim db As DAO.Database, t As TableDef, ws As DAO.Workspace
Dim Q As QueryDef, c  As Container
Dim Msg As String
Dim procname As String

Found_Object% = -1
procname = "ObjectExists"

If SomethingInS(MyDBName) = True Then
    ' param2=network user, p3=password
    Set ws = CreateWorkspace("JetWorkspace", "", "", dbUseJet) ' <=== Error here
    Set db = ws.OpenDatabase(MyDBName) ' Destination MDB file.
Else
    Set db = CurrentDb() ' Destination MDB file is same as source?
End If

Select Case ObjectType$
Case "Tables"
    Find_Object = db.TableDefs(ObjectName$).Name

Case "Queries"
    Find_Object = db.QueryDefs(ObjectName$).Name

Case Else
    If ObjectType$ = "Forms" Then
        ObjectNum = 1 ' ObjectNum used below in db.containers(ObjectNum)
    ElseIf ObjectType$ = "Modules" Then
        ObjectNum = 2
    ElseIf ObjectType$ = "Reports" Then

        ObjectNum = 4
    ElseIf ObjectType$ = "Macros" Then
        ObjectNum = 5
    Else
         Msg = procname & ": Object Name """ & ObjectType & """ is an invalid"
         Msg = Msg & " argument to function ObjectExists!"
         MsgBox Msg, 16, "ObjectExists"
         Exit Function

    End If

    Set c = db.Containers(ObjectNum)
    Find_Object = c.Documents(ObjectName$).Name

End Select

If Err = 3265 Or Find_Object = "" Then
    Found_Object% = 0 ' false
End If

ObjectExists = Found_Object%
db.Close
Set db = Nothing
Set t = Nothing
Set Q = Nothing
Set c = Nothing
If SomethingInS(MyDBName) = True Then
    ws.Close
    Set ws = Nothing
End If

Exit Function

MyError:
' 3029=Not a valid account name or password.
If Err.Number = 3029 Then
    Resume Next
Else
    Msg = procname & ": " & Err.Number & " " & Err.Description
    MsgBox Msg
    ObjectExists = -1
    Exit Function
End If

End Function

Wait, the variable of type Database and Workspaces is not a DAO type and I only use DAO. I'll try that. (That didn't work. I still got an error "3029 Not a valid account name or password".)
 
Last edited:
Access 2003 on Win XP

I have a test MDB file where I do all my work. When my changes are done, I want to copy the changed objects (forms, queries, reports, modules, etc) to the "work" MDB file.

My current code from Access95/97 is not working. It seems to want an Access username and password. But I would like a way to transfer these objects without setting up Access security. We have problems/bugs with A2003 and MDB files on a network drive, and I want to avoid all those headaches.

How can I transfer an Access object from my MDB on a C: drive to an MDB on my network drive (mapped as a drive letter)?

Below is a picture of my current screen.
UTLupdatever.jpg


I click the Forms, Queries, or Reports button to get a list of that object. The list appears in the left hand list box. When I double click the item in the left list box, it gets transferred to the new MDB file and put in the right list box.

The 2 text boxes above show the current MDB file and the destination MDB file. Filenames erased for privacy.

My problem is, in my current routine (I got it from the internet), it uses an ObjectExists routine, which opens the destination MDB and requires an Access username and password. Here is the first part of the code in ObjectExists:
Code:
 Function ObjectExists(ObjectType$, ObjectName$, Optional MyDBName As String) As Integer
' Returns TRUE (-1) if an object exists in the current DB. Otherwise
' returns FALSE (0).
' Object type: can be Tables, Queries, Forms, Modules, Reports, Macros
' Object name: Name of object to look for.
' DBName: name of MDB file to check.

'On Error Resume Next
On Error GoTo MyError

Dim Found_Object%, Find_Object As String, ObjectNum As Integer
Dim db As DAO.Database, t As TableDef, ws As DAO.Workspace
Dim Q As QueryDef, c  As Container
Dim Msg As String
Dim procname As String

Found_Object% = -1
procname = "ObjectExists"

If SomethingInS(MyDBName) = True Then
    ' param2=network user, p3=password
    Set ws = CreateWorkspace("JetWorkspace", "", "", dbUseJet) ' <=== Error here
    Set db = ws.OpenDatabase(MyDBName) ' Destination MDB file.
Else
    Set db = CurrentDb() ' Destination MDB file is same as source?
End If

Select Case ObjectType$
Case "Tables"
    Find_Object = db.TableDefs(ObjectName$).Name

Case "Queries"
    Find_Object = db.QueryDefs(ObjectName$).Name

Case Else
    If ObjectType$ = "Forms" Then
        ObjectNum = 1 ' ObjectNum used below in db.containers(ObjectNum)
    ElseIf ObjectType$ = "Modules" Then
        ObjectNum = 2
    ElseIf ObjectType$ = "Reports" Then

        ObjectNum = 4
    ElseIf ObjectType$ = "Macros" Then
        ObjectNum = 5
    Else
         Msg = procname & ": Object Name """ & ObjectType & """ is an invalid"
         Msg = Msg & " argument to function ObjectExists!"
         MsgBox Msg, 16, "ObjectExists"
         Exit Function

    End If

    Set c = db.Containers(ObjectNum)
    Find_Object = c.Documents(ObjectName$).Name

End Select

If Err = 3265 Or Find_Object = "" Then
    Found_Object% = 0 ' false
End If

ObjectExists = Found_Object%
db.Close
Set db = Nothing
Set t = Nothing
Set Q = Nothing
Set c = Nothing
If SomethingInS(MyDBName) = True Then
    ws.Close
    Set ws = Nothing
End If

Exit Function

MyError:
' 3029=Not a valid account name or password.
If Err.Number = 3029 Then
    Resume Next
Else
    Msg = procname & ": " & Err.Number & " " & Err.Description
    MsgBox Msg
    ObjectExists = -1
    Exit Function
End If

End Function

Wait, the variable of type Database and Workspaces is not a DAO type and I only use DAO. I'll try that. (That didn't work. I still got an error "3029 Not a valid account name or password".)

To me it looks like there is a Username and Password required for the Network-based database, indicating some level of security on the process for updating the "work" objects. Have you tried using your "work" username/password?
 
Yes, I tried using my Windows network username and password. But the CreateWorkspace function might be looking at an Access username and password, that's my guess anyway.

Please keep in mind I don't want to update ALL objects in an MDB file, like some other tools do. I just want to pick the ones I changed and copy those from the current MDB file to a production MDB file.
 
Yes, I tried using my Windows network username and password. But the CreateWorkspace function might be looking at an Access username and password, that's my guess anyway.

Please keep in mind I don't want to update ALL objects in an MDB file, like some other tools do. I just want to pick the ones I changed and copy those from the current MDB file to a production MDB file.

Yes, according to Access Help , if you create a workspace this is the syntax:

Set workspace = CreateWorkspace(name, user, password, type)

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


"admin", "" is the default password, give it a try.

I don't use CreateWorkspace(....),
I usually just use
Set ws = DBEngine.Workspaces(0)
 
You shouldn't need to use the Workspaces object. And you shouldn't need to deal with any kind of security if there is none set on the object.

Take a look at my backend auto updater and then use whatever you can, modified as needed, to do what you want. Here's the documentation too.
 

Users who are viewing this thread

Back
Top Bottom