jaydwest
06-09-2007, 03:18 PM
Change is tough. I have some old databases that use the following code:
SendKeys "%FO" & strDBPathName & "~", False
This is real old code so only old timers will recognize it. But I want to open a new Access database from the current Access database and close the current database.
What is the new code to do this.
Thanks for your help
pbaldy
06-09-2007, 05:50 PM
Try Shell or FollowHyperlink.
jaydwest
06-10-2007, 07:35 AM
Thanks for your suggestions. Have tried them. THey all seem to work but get hung up on the new MS Access security stuff.
THe SendKeys actually does work but I get the message "Permission Denied." The followHyperlink gets locked up.
SO I guess the new question is - Is there any way to bypass the new Warning messages that MS Access now uses?
jaydwest
06-10-2007, 06:42 PM
KEYWORDS: Open Database, Open FIle
After further reseach I came up with the following function that uses the Shell Command and does work.
'------ JW070610(B1)
Public Function OpenDB(pasDBPathName As String, pasCloseCurrent As String) As String
On Error GoTo Err_Proc
'-- Test Required Data
If Ns(pasDBPathName, "None") = "None" Then
myM = "DATABASE PATH NAME NOT FOUND. "
Alert
OpenDB = "ERROR"
Exit Function
End If
If Not FileExists(pasDBPathName) Then
myM = "DATABASE WAS NOT FOUND IN THE FOLDER SHOWN (" & pasDBPathName & "). "
Alert
OpenDB = "ERROR"
Exit Function
End If
Call Shell("msaccess.exe " & pasDBPathName, vbMaximizedFocus)
DoEvents
Select Case pasCloseCurrent
Case "Close", "CloseCurrent"
DoCmd.Quit
End Select
Exit Function
Err_Proc:
msg Error
Exit Function
End Function
--------------------------------------------
I would appreciate it if anyone has a better way to do this (Like Using MS Access Objects instead of the Shell Command)
Also would like to know if there is a solution to opening another database in code and bypassing the security warning and logon forms. In the case of the logon Popup, the SendKeys method did bypass it and after all you have already logged into the current dbs.
Thanks for all your help
chergh
06-10-2007, 11:29 PM
Try this:
dim accapp as access.application
set accapp = new access.application
accapp.opencurrentdatabase("c:\whatever\blah.mdb")
accapp.visible = true
jaydwest
06-11-2007, 07:07 AM
I already tried using an Access Application, but it locks up the current Access Database when the Logon Dialog Box pops up. It is modal and prevents closing the current db or doing anything with it. Had to use Task Manager to shut it down.
boblarson
06-11-2007, 07:12 AM
Also would like to know if there is a solution to opening another database in code and bypassing the security warning...
The only way to get past this is to either
1. Set the user's Macro Security Level to LOW (not overly optimal nor allowed by many IT Departments with good reason)
2. Digitally sign the file, but to really do so requires some third-party certificate (although I THINK you can create your own which will work on your own machine and it may work on someone else's if they manually install it).
jaydwest
06-11-2007, 07:19 AM
Bob,
Thanks for your response. Do your suggestions apply to using an Access Application or to the Shell Function?
Or were you referring to the Security Warning and Logon Popup issues?
Thanks.
KingRudeDog
06-29-2007, 04:26 AM
Bob,
Thanks for your response. Do your suggestions apply to using an Access Application or to the Shell Function?
Or were you referring to the Security Warning and Logon Popup issues?
Thanks.
I know this may sound silly, after all I am more of a novice programmer than all of you. But...I picked up this much simpler code on this forum from a Windows OpenFile dialogue and pirated this portion of the code. Im not sure if it will work on the older databases or not. But it works on the new.
On Event:
Me.tbHidden.SetFocus
'sets focus to a hidden textbox (tbHidden)
If IsNull (txtbox) Or txtbox = "" Then
MsgBox "Please enter a valid path."
Else OpenFile (txtbox)
End If
I actually do open another access database with this one (from inside an access db)
boblarson
06-29-2007, 06:34 AM
Or were you referring to the Security Warning and Logon Popup issues?
I was referring to the security warning and logon popup issues.