Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a NEW / different Database

Status
Not open for further replies.

darinmc

Technical User
Feb 27, 2005
171
GB
Hi
---Reason behind this is to open a different DB and Update the original 1 using filecopy---

I used this code last night, it seemed to work fine, However, today at work its not doing anything?
Code:
Dim appAccess As New Access.Application

appAccess.OpenCurrentDatabase ("C:\Lynx\Test1.mde")
'--This command CLOSES the DATABASE---   
 DoCmd.Quit

I therefore tried this, thinking it might do the job.. Still nothing!!!
Could there be a reference missing in VB code area?
Is there something wrong with my code??

Code:
Private Sub cmdUpdateDB_Click()
Dim VarPassword As Variant
'Dim appAccess As New Access.Application
VarPassword = DLookup("[UpdateDatabase]", "tblPassword", "[PasswordID] = [Forms]![frmSwitchboard]![tPassID]")
Dim appAccess As Access.Application
    Dim strDB As String
    ' Initialize string to database path.
    Const strConPathToSamples = "C:\Lynx\"
    strDB = strConPathToSamples & "LynxFormsServerUPDATE.mdb"
    ' Create new instance of Microsoft Access.
    Set appAccess = _
        CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
If VarPassword = 0 Then
'message box
MsgBox "This form is restricted to Database Administrator"
Else
Select Case Me.cmdUpdateDB.Caption
Case "NO Update available"
MsgBox "No Update at this time"
Case "DATABASE UPDATE AVAILABLE"
MsgBox "Going to Update the database now"
    appAccess.OpenCurrentDatabase strDB
'--This command CLOSES the DATABASE---
DoCmd.Quit

End Select
End If
End Sub

Hope you can help
Plz
Thx, Darin
 
The only line jumping out at me is

Code:
VarPassword = DLookup("[UpdateDatabase]", "tblPassword", "[PasswordID] = [Forms]![frmSwitchboard]![tPassID]")

Seems like it should be...

Code:
VarPassword = DLookup("[UpdateDatabase]", "tblPassword", "[PasswordID] = " & [Forms]![frmSwitchboard]![tPassID])

Your version may work. Do you get an error? What happens when you step through it / Or where does it seem to go wrong or do something unexpected?
 
Hi the Varpassword does work fine.

However, this is baffling me..

Code:
Sub DisplayForm()

    Dim strDB As String
Dim appAccess As Access.Application
    ' Initialize string to database path.
    Const strConPathToSamples = "C:\1\"
    'Const strConPathToSamples = "C:\Program " _
        & "Files\Microsoft Office\Office11\Samples\"
    strDB = strConPathToSamples & "TESTrecordset.mdb"
    'strDB = strConPathToSamples & "Northwind.mdb"
    ' Create new instance of Microsoft Access.
    Set appAccess = _
        CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strDB
    ' Open Orders form.
    'appAccess.DoCmd.OpenForm "Form1"
End Sub

Private Sub cmdCloseDB_Click()
DisplayForm
End Sub

When I use it to open the northwind file = NO PROBLEM

BUT

when i try open my database, it opens at the security message, i press ok and it closes straight away!!!
It also leaves the.ldb file in the directory, making me go to ctl alt del, having to delete reference to ACCESS, then I can delete the file...

What i'm trying to do, is open another Database and close the current one i'm working with in 1 click of a button...

Any help, well appreciated

Thx
Darin
 
Looking at some of my old code it looks like you need to make the application visible...


Code:
Sub DisplayForm()

	Dim strDB As String
	Dim appAccess As Access.Application
	' Initialize string to database path.
	Const strConPathToSamples = "C:\1\"
	strDB = strConPathToSamples & "TESTrecordset.mdb"
	' Create new instance of Microsoft Access.
	Set appAccess = CreateObject("Access.Application")
	[b][i]appAccess.visible = True[/i][/b]
	' Open database in Microsoft Access window.
	appAccess.OpenCurrentDatabase strDB
	' Open Orders form.
	'appAccess.DoCmd.OpenForm "Form1"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top