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

2 Questions: Open Dialog, Update subform

Status
Not open for further replies.
Sep 21, 2001
28
US
I have 2 questions:

1) I need the vb code or macro which will allow me to open the open dialog window from Access so I can open other documents from excels, words, and etc. The reason I need to do this is because I created a template from MS Word, which will retrive the data from Access table and mail merge into word document. I am unable to find the source code which could perform the mail merge automatically. So I figure if I can get the open dialog window open, the user can select the template and perform the mail merge manually.

2) I have a Main Form, which contains a subform referencing from a query I created. I wonder is it possible for me to delete or update records from that subform. If so, what changes do I need to perform in order for update and delete function to work.

Thanks
 
To display a file open dialog, use GetOpenFileName API call. Search Microsoft KB for syntax, something like:

Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

'constants for file open dialog
Global Const OFN_READONLY = &H1
Global Const OFN_OVERWRITEPROMPT = &H2
Global Const OFN_HIDEREADONLY = &H4
Global Const OFN_NOCHANGEDIR = &H8
Global Const OFN_SHOWHELP = &H10
Global Const OFN_ENABLEHOOK = &H20
Global Const OFN_ENABLETEMPLATE = &H40
Global Const OFN_ENABLETEMPLATEHANDLE = &H80
Global Const OFN_NOVALIDATE = &H100
Global Const OFN_ALLOWMULTISELECT = &H200
Global Const OFN_EXTENSIONDIFFERENT = &H400
Global Const OFN_PATHMUSTEXIST = &H800
Global Const OFN_FILEMUSTEXIST = &H1000
Global Const OFN_CREATEPROMPT = &H2000
Global Const OFN_SHAREAWARE = &H4000
Global Const OFN_NOREADONLYRETURN = &H8000
Global Const OFN_NOTESTFILECREATE = &H10000

Global Const OFN_SHAREFALLTHROUGH = 2
Global Const OFN_SHARENOWARN = 1
Global Const OFN_SHAREWARN = 0


Function SelectFile (i_strFilter as string) as string

Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim sFileName As String

'set openfilename structure values
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = <Calling Form Handle>
OpenFile.hInstance = 0
OpenFile.lpstrFilter = i_strFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = &quot;*.*&quot; & String(254, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = &quot;&quot;
OpenFile.lpstrTitle = <dialog Title>
OpenFile.flags = OFN_HIDEREADONLY + OFN_PATHMUSTEXIST + OFN_NOVALIDATE + OFN_NOCHANGEDIR

'load open file dialog
lReturn = GetOpenFileName(OpenFile)

SelectFile = OpenFile.lpstrFile
End Function

Hope this helps.

:)

 
Thanks for the reply. I've been waiting for someone to help me on this problem for quite some time now.

I've searched through the forums, Microsoft Knowledge Base, MSDN, and etc, but still unable to find what I'm looking for.

A lot of the code I received allow me to get the open dialog box after clicking a button, but when selecting a file, I am unable to open that selected file.

E.g. After the open dialog box appears and selects a word document, I would like MS Word to open that document. Same applies to excel, powerpoint, text file, etc.

I'm really stuck to get this function working, so any help would be deeply appreciated.

 
Bonusmarch,

Use the ActiveX component MS Common Dialog Control. This can be used to open any of the standard dialog boxes (i.e. open file, save file, print control, etc.)

HTH

Craig
 
Yes, I got that MS Common Dialog Control on the form already, but my problem is getting that selected file to open. Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top