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

File open dialog and update form, from Newbie

Status
Not open for further replies.

foocat

Programmer
Sep 30, 2002
1
US
Help,



I am trying to have a (file open box) to get a file path and store that information into a table.

I have read these topics, however, I am not advanced to understand how to do these things


On my form there is a field with the control source set to "1" on my table. I also have a button linked to the code below that opens the file open box. and returns a MSGBOX with the file path.


How do i put that information into my form that will update the table using a Module?






Please be as specific as possable.


Thanks


Foocat



going on 5 hours now!!!










Here is my code

Option Compare Database

Option Explicit

Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Private 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

Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_SHAREAWARE = &H4000
Public Const OFN_CREATEPROMPT = &H2000
Private Const MAX_PATH = 260

Public Function getfile(Optional InitialDir As String, _
Optional FilterMessage As String = "Choose File", _
Optional FilterSkelton As String = "*.*", _
Optional File As String = "File Name", _
Optional Title As String = "Use the Open Button to Select") As String
getfile = getPath(CurDir$, FilterMessage, FilterSkelton, File, Title)
End Function

Public Function getPath( _
Optional InitialDir As String, _
Optional FilterMessage As String = "Choose Folder Only", _
Optional FilterSkelton As String = "*|*", _
Optional File As String = "Folders Only", _
Optional Title As String = "Use the Open Button to Select") As String
Dim CommDlgError As Long
Dim OFN As OPENFILENAME
If Len(InitialDir) = 0 Then InitialDir = CurDir$()
With OFN
.lStructSize = Len(OFN)
.lpstrFilter = FilterMessage & vbNullChar & FilterSkelton & String(2, vbNullChar)
.lpstrFile = File & String(MAX_PATH - Len(File), vbNullChar)
.nMaxFile = MAX_PATH
.lpstrInitialDir = InitialDir & vbNullChar
.lpstrTitle = Title
.lpstrFileTitle = String(MAX_PATH, vbNullChar)
.nMaxFileTitle = MAX_PATH
.Flags = OFN_HIDEREADONLY Or OFN_NOCHANGEDIR Or OFN_SHAREAWARE
If GetOpenFileName(OFN) <> 0 Then
' .lpstrFileTitle conatins file name only
If FilterSkelton = &quot;*|*&quot; Then
getPath = Left(.lpstrFile, .nFileOffset)
Else
getPath = .lpstrFile
End If
Else
CommDlgError = CommDlgExtendedError
' if not just a cancel
If CommDlgError <> 0 Then
MsgBox &quot;Common Dialog Error # &quot; & CommDlgError & vbCrLf & vbCrLf & &quot;Consult Common Dialog Documumentation&quot; & vbCrLf & &quot;(in MSDN Library)&quot; & vbCrLf & vbCrLf & &quot;for meaning.&quot;, vbCritical, &quot;Cyriv Solutions&quot;
End If
End If
End With
End Function

Sub testgetPath()
MsgBox getPath
End Sub

Sub testgetFile()
MsgBox getfile()
End Sub
 
Hi,
I have used DAO to record the info in the table ( I call it tblPath).

Put the folllowing code in the Click event of a comand button named recordPath.

Private Sub recordPath_Click()
Dim db as DAO.Database
Dim rs as DAO.Recordset
Set db=CurrentDB
Set rs=db.OpenRecordset(&quot;tblPath&quot;,dbOpenDynaset)
rs.AddNew
rs.Fields(&quot;getPath&quot;)=getpath() 'Your Function
rs.Fields(&quot;getFile&quot;)=getFile() 'Your function
rs.Update
rs.CLose
db.CLose
Set rs=Nothing
Set db=Nothing
MsgBox &quot;Path recorded successfully in tblPath&quot;
End Sub

You must set a reference to the MS DAO 3.6 Object Library through Tools->References in the VB Editor. Hope it helps. Let me know what happens.
With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top