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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is this expert? opening a db from another, part 2

Status
Not open for further replies.

downwitchyobadself

Programmer
Aug 1, 2001
159
0
0
US
Sorry, it won't register my posts on this thread????

thread181-262408 still trying to do something very simple, as described in that thread: click a button in an app, and have it open another app, within the same Access window.

I know how to do it opening a second copy of Access, and just minimizing the first app, but I don't understand why I should have to blow system resources to do something unbelievably simple. What's more, the second instance of Access tends not to open maximized, and that's an absolute necessity for me: if it can't be done in a single window (why can you do something off a menu that you can't do on a button?!?!), I have to at least be able to get the window full-size, and the db's opening form centered... ARRGHH.
 
Copy this function to a new module.

Function GetOpenFile(Optional varDirectory As Variant, _
Optional varTitleForDialog As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varfilename As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUSTEXIST Or _
ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
If IsMissing(varDirectory) Then
varDirectory = ""
End If
If IsMissing(varTitleForDialog) Then
varTitleForDialog = ""
End If

' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
strFilter = ahtAddFilterItem(strFilter, _
"access (*.mdb)", "*.MDB")
' Now actually call to get the file name.
varfilename = ahtCommonFileOpenSave( _
OpenFile:=True, _
InitialDir:=varDirectory, _
Filter:=strFilter, _
Flags:=lngFlags, _
DialogTitle:=varTitleForDialog)
If Not IsNull(varfilename) Then
varfilename = TrimNull(varfilename)
End If
GetOpenFile = varfilename
End Function

'Then add this code to the on_click event of a command button to open database.'

On Error GoTo Err_Command27_Click

Dim STRDEST As String
Dim std
Dim dblNew As Double, strAccDB As String
Dim strAccLoc As String

STRDEST = GetOpenFile
If Len(STRDEST) = 0 Then
GoTo Err_Command27_Click
Else
strAccDB = """" & STRDEST & """"
strAccLoc = SysCmd(acSysCmdAccessDir) & "MSACCESS.exe"
dblNew = shell(strAccLoc & " " & strAccDB, vbNormalFocus)
Application.Quit
End If
Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
Resume Exit_Command27_Click

'Make sure to change all the Command27 entries to your command #.'
 
Forgot to tell you to make sure you have the "Microsoft shell commands and automation" reference checked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top