If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Need a Delete Button?
On my form I have an button to Browse my Computer and an Open Button
that allows me to open the file I have associated on my Computer. The browse button also places the name of the file into a a field named tbFileName on my form. My question is, once I associated this file there is no way to unassociate it on this form. Is there a way to delete this with a delete button? Here is my code. Any help would greatly be appreciated. Thanks. -------------------------------------------------------------------------------------------------- Private Sub bBrowse_Click() On Error GoTo Err_bBrowse_Click Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant ' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _ ' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" ' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*" strFilter = "All Files (*.*)" & vbNullChar & "*.*" lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly varFileName = tsGetFileFromUser( _ fOpenFile:=True, _ strFilter:=strFilter, _ rlngflags:=lngFlags, _ strDialogTitle:="Find File (Select The File And Click The Open Button)") If IsNull(varFileName) Or varFileName = "" Then Debug.Print "User pressed 'Cancel'." Beep MsgBox "File selection was canceled.", vbInformation Exit Sub Else 'Debug.Print varFileName tbFile = varFileName End If Call ParseFileName Exit_bBrowse_Click: Exit Sub Err_bBrowse_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bBrowse_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub bOpenFile_Click() On Error GoTo Err_bOpen_Click If IsNull(tbFile) Or tbFile = "" Then MsgBox "Please browse and select a valid file to open.", vbCritical, "Invalid File" Else OpenFile (tbFile) End If Exit_bOpen_Click: Exit Sub Err_bOpen_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bOpen_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub ParseFileName() On Error GoTo Err_ParseFileName Dim sFullName As String Dim sFilePathOnly As String Dim sDrive As String Dim sPath As String Dim sLocation As String Dim sFileName As String sFullName = tbFile.Value ' Find the final "\" in the path. sPath = sFullName Do While Right$(sPath, 1) "\" sPath = Left$(sPath, Len(sPath) - 1) Loop ' Find the Drive. sDrive = Left$(sFullName, InStr(sFullName, ":") + 1) 'tbDrive = sDrive ' Find the Location. sLocation = Mid$(sPath, Len(sDrive) - 2) 'tbLocation = sLocation ' Find the Path. sPath = Mid$(sPath, Len(sDrive) + 1) 'tbPath = sPath ' Find the file name. sFileName = Mid$(sFullName, Len(sPath) + 4) tbFileName = sFileName Exit_ParseFileName: Exit Sub Err_ParseFileName: MsgBox Err.Number & " - " & Err.Description Resume Exit_ParseFileName End Sub |
#2
|
|||
|
|||
Need a Delete Button?
You could set tbFile = "", but it looks like you're trapping that as an
error. Mike wrote: On my form I have an button to Browse my Computer and an Open Button that allows me to open the file I have associated on my Computer. The browse button also places the name of the file into a a field named tbFileName on my form. My question is, once I associated this file there is no way to unassociate it on this form. Is there a way to delete this with a delete button? Here is my code. Any help would greatly be appreciated. Thanks. -------------------------------------------------------------------------------------------------- Private Sub bBrowse_Click() On Error GoTo Err_bBrowse_Click Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant ' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _ ' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" ' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*" strFilter = "All Files (*.*)" & vbNullChar & "*.*" lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly varFileName = tsGetFileFromUser( _ fOpenFile:=True, _ strFilter:=strFilter, _ rlngflags:=lngFlags, _ strDialogTitle:="Find File (Select The File And Click The Open Button)") If IsNull(varFileName) Or varFileName = "" Then Debug.Print "User pressed 'Cancel'." Beep MsgBox "File selection was canceled.", vbInformation Exit Sub Else 'Debug.Print varFileName tbFile = varFileName End If Call ParseFileName Exit_bBrowse_Click: Exit Sub Err_bBrowse_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bBrowse_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub bOpenFile_Click() On Error GoTo Err_bOpen_Click If IsNull(tbFile) Or tbFile = "" Then MsgBox "Please browse and select a valid file to open.", vbCritical, "Invalid File" Else OpenFile (tbFile) End If Exit_bOpen_Click: Exit Sub Err_bOpen_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bOpen_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub ParseFileName() On Error GoTo Err_ParseFileName Dim sFullName As String Dim sFilePathOnly As String Dim sDrive As String Dim sPath As String Dim sLocation As String Dim sFileName As String sFullName = tbFile.Value ' Find the final "\" in the path. sPath = sFullName Do While Right$(sPath, 1) "\" sPath = Left$(sPath, Len(sPath) - 1) Loop ' Find the Drive. sDrive = Left$(sFullName, InStr(sFullName, ":") + 1) 'tbDrive = sDrive ' Find the Location. sLocation = Mid$(sPath, Len(sDrive) - 2) 'tbLocation = sLocation ' Find the Path. sPath = Mid$(sPath, Len(sDrive) + 1) 'tbPath = sPath ' Find the file name. sFileName = Mid$(sFullName, Len(sPath) + 4) tbFileName = sFileName Exit_ParseFileName: Exit Sub Err_ParseFileName: MsgBox Err.Number & " - " & Err.Description Resume Exit_ParseFileName End Sub |
#3
|
|||
|
|||
Need a Delete Button?
What do you mean by "unassociate it on this form"? Remove the value from
tbFileName, or something else? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mike" wrote in message oups.com... On my form I have an button to Browse my Computer and an Open Button that allows me to open the file I have associated on my Computer. The browse button also places the name of the file into a a field named tbFileName on my form. My question is, once I associated this file there is no way to unassociate it on this form. Is there a way to delete this with a delete button? Here is my code. Any help would greatly be appreciated. Thanks. -------------------------------------------------------------------------------------------------- Private Sub bBrowse_Click() On Error GoTo Err_bBrowse_Click Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant ' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _ ' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" ' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*" strFilter = "All Files (*.*)" & vbNullChar & "*.*" lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly varFileName = tsGetFileFromUser( _ fOpenFile:=True, _ strFilter:=strFilter, _ rlngflags:=lngFlags, _ strDialogTitle:="Find File (Select The File And Click The Open Button)") If IsNull(varFileName) Or varFileName = "" Then Debug.Print "User pressed 'Cancel'." Beep MsgBox "File selection was canceled.", vbInformation Exit Sub Else 'Debug.Print varFileName tbFile = varFileName End If Call ParseFileName Exit_bBrowse_Click: Exit Sub Err_bBrowse_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bBrowse_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub bOpenFile_Click() On Error GoTo Err_bOpen_Click If IsNull(tbFile) Or tbFile = "" Then MsgBox "Please browse and select a valid file to open.", vbCritical, "Invalid File" Else OpenFile (tbFile) End If Exit_bOpen_Click: Exit Sub Err_bOpen_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bOpen_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub ParseFileName() On Error GoTo Err_ParseFileName Dim sFullName As String Dim sFilePathOnly As String Dim sDrive As String Dim sPath As String Dim sLocation As String Dim sFileName As String sFullName = tbFile.Value ' Find the final "\" in the path. sPath = sFullName Do While Right$(sPath, 1) "\" sPath = Left$(sPath, Len(sPath) - 1) Loop ' Find the Drive. sDrive = Left$(sFullName, InStr(sFullName, ":") + 1) 'tbDrive = sDrive ' Find the Location. sLocation = Mid$(sPath, Len(sDrive) - 2) 'tbLocation = sLocation ' Find the Path. sPath = Mid$(sPath, Len(sDrive) + 1) 'tbPath = sPath ' Find the file name. sFileName = Mid$(sFullName, Len(sPath) + 4) tbFileName = sFileName Exit_ParseFileName: Exit Sub Err_ParseFileName: MsgBox Err.Number & " - " & Err.Description Resume Exit_ParseFileName End Sub |
#4
|
|||
|
|||
Need a Delete Button?
I know my terms are not correct. I just do not want the form showing
the name of a file if I mistakenly associate/ link it. See once I find the file I want and click OPEN. The file parses itself to the file name and deletes the rest of the path. But sometimes I attach/associate/link the wrong file and then I want to be able to DELETE it, so it does not show the file name. Can someone help me delete it from the form. Make Sense? I wish I could show you with a picture. Douglas J. Steele wrote: What do you mean by "unassociate it on this form"? Remove the value from tbFileName, or something else? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mike" wrote in message oups.com... On my form I have an button to Browse my Computer and an Open Button that allows me to open the file I have associated on my Computer. The browse button also places the name of the file into a a field named tbFileName on my form. My question is, once I associated this file there is no way to unassociate it on this form. Is there a way to delete this with a delete button? Here is my code. Any help would greatly be appreciated. Thanks. -------------------------------------------------------------------------------------------------- Private Sub bBrowse_Click() On Error GoTo Err_bBrowse_Click Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant ' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _ ' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" ' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*" strFilter = "All Files (*.*)" & vbNullChar & "*.*" lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly varFileName = tsGetFileFromUser( _ fOpenFile:=True, _ strFilter:=strFilter, _ rlngflags:=lngFlags, _ strDialogTitle:="Find File (Select The File And Click The Open Button)") If IsNull(varFileName) Or varFileName = "" Then Debug.Print "User pressed 'Cancel'." Beep MsgBox "File selection was canceled.", vbInformation Exit Sub Else 'Debug.Print varFileName tbFile = varFileName End If Call ParseFileName Exit_bBrowse_Click: Exit Sub Err_bBrowse_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bBrowse_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub bOpenFile_Click() On Error GoTo Err_bOpen_Click If IsNull(tbFile) Or tbFile = "" Then MsgBox "Please browse and select a valid file to open.", vbCritical, "Invalid File" Else OpenFile (tbFile) End If Exit_bOpen_Click: Exit Sub Err_bOpen_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bOpen_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub ParseFileName() On Error GoTo Err_ParseFileName Dim sFullName As String Dim sFilePathOnly As String Dim sDrive As String Dim sPath As String Dim sLocation As String Dim sFileName As String sFullName = tbFile.Value ' Find the final "\" in the path. sPath = sFullName Do While Right$(sPath, 1) "\" sPath = Left$(sPath, Len(sPath) - 1) Loop ' Find the Drive. sDrive = Left$(sFullName, InStr(sFullName, ":") + 1) 'tbDrive = sDrive ' Find the Location. sLocation = Mid$(sPath, Len(sDrive) - 2) 'tbLocation = sLocation ' Find the Path. sPath = Mid$(sPath, Len(sDrive) + 1) 'tbPath = sPath ' Find the file name. sFileName = Mid$(sFullName, Len(sPath) + 4) tbFileName = sFileName Exit_ParseFileName: Exit Sub Err_ParseFileName: MsgBox Err.Number & " - " & Err.Description Resume Exit_ParseFileName End Sub |
#5
|
|||
|
|||
Need a Delete Button?
Sorry, it still doesn't make sense to me.
You're putting the file name in the field named tbFileName on your form. Are you saying that you want to remove that name from that field? Add a button to your form, and put Me.tbFileName = Null in the Click event. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mike" wrote in message ups.com... I know my terms are not correct. I just do not want the form showing the name of a file if I mistakenly associate/ link it. See once I find the file I want and click OPEN. The file parses itself to the file name and deletes the rest of the path. But sometimes I attach/associate/link the wrong file and then I want to be able to DELETE it, so it does not show the file name. Can someone help me delete it from the form. Make Sense? I wish I could show you with a picture. Douglas J. Steele wrote: What do you mean by "unassociate it on this form"? Remove the value from tbFileName, or something else? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mike" wrote in message oups.com... On my form I have an button to Browse my Computer and an Open Button that allows me to open the file I have associated on my Computer. The browse button also places the name of the file into a a field named tbFileName on my form. My question is, once I associated this file there is no way to unassociate it on this form. Is there a way to delete this with a delete button? Here is my code. Any help would greatly be appreciated. Thanks. -------------------------------------------------------------------------------------------------- Private Sub bBrowse_Click() On Error GoTo Err_bBrowse_Click Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant ' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _ ' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" ' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*" strFilter = "All Files (*.*)" & vbNullChar & "*.*" lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly varFileName = tsGetFileFromUser( _ fOpenFile:=True, _ strFilter:=strFilter, _ rlngflags:=lngFlags, _ strDialogTitle:="Find File (Select The File And Click The Open Button)") If IsNull(varFileName) Or varFileName = "" Then Debug.Print "User pressed 'Cancel'." Beep MsgBox "File selection was canceled.", vbInformation Exit Sub Else 'Debug.Print varFileName tbFile = varFileName End If Call ParseFileName Exit_bBrowse_Click: Exit Sub Err_bBrowse_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bBrowse_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub bOpenFile_Click() On Error GoTo Err_bOpen_Click If IsNull(tbFile) Or tbFile = "" Then MsgBox "Please browse and select a valid file to open.", vbCritical, "Invalid File" Else OpenFile (tbFile) End If Exit_bOpen_Click: Exit Sub Err_bOpen_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bOpen_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub ParseFileName() On Error GoTo Err_ParseFileName Dim sFullName As String Dim sFilePathOnly As String Dim sDrive As String Dim sPath As String Dim sLocation As String Dim sFileName As String sFullName = tbFile.Value ' Find the final "\" in the path. sPath = sFullName Do While Right$(sPath, 1) "\" sPath = Left$(sPath, Len(sPath) - 1) Loop ' Find the Drive. sDrive = Left$(sFullName, InStr(sFullName, ":") + 1) 'tbDrive = sDrive ' Find the Location. sLocation = Mid$(sPath, Len(sDrive) - 2) 'tbLocation = sLocation ' Find the Path. sPath = Mid$(sPath, Len(sDrive) + 1) 'tbPath = sPath ' Find the file name. sFileName = Mid$(sFullName, Len(sPath) + 4) tbFileName = sFileName Exit_ParseFileName: Exit Sub Err_ParseFileName: MsgBox Err.Number & " - " & Err.Description Resume Exit_ParseFileName End Sub |
#6
|
|||
|
|||
Need a Delete Button?
"Mike" wrote in message ups.com... I know my terms are not correct. I just do not want the form showing the name of a file if I mistakenly associate/ link it. See once I find the file I want and click OPEN. The file parses itself to the file name and deletes the rest of the path. But sometimes I attach/associate/link the wrong file and then I want to be able to DELETE it, so it does not show the file name. Can someone help me delete it from the form. Make Sense? I wish I could show you with a picture. I suspect you are confusing the issue by focusing on the Form... Forms are for entering and displaying data that is stored in Tables and retrieved with Queries. (Forms can be "unbound" for other purposes, but yours does not seem to be unbound, from what you say.) My guess is that you are having difficulties because the information you entered on the Form is already saved to the Table, and what you really need to do is to delete the Record from the Table. Do you sometimes discover the error after closing the data entry Form, and then want to delete it? If so, you will have to remove the Record from the Table, not just the value from the Form. Larry Linson Microsoft Access MVP |
#7
|
|||
|
|||
Need a Delete Button?
Perfect! Did not think it would be that easy!!!
Thanks! Mike Douglas J. Steele wrote: Sorry, it still doesn't make sense to me. You're putting the file name in the field named tbFileName on your form. Are you saying that you want to remove that name from that field? Add a button to your form, and put Me.tbFileName = Null in the Click event. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mike" wrote in message ups.com... I know my terms are not correct. I just do not want the form showing the name of a file if I mistakenly associate/ link it. See once I find the file I want and click OPEN. The file parses itself to the file name and deletes the rest of the path. But sometimes I attach/associate/link the wrong file and then I want to be able to DELETE it, so it does not show the file name. Can someone help me delete it from the form. Make Sense? I wish I could show you with a picture. Douglas J. Steele wrote: What do you mean by "unassociate it on this form"? Remove the value from tbFileName, or something else? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mike" wrote in message oups.com... On my form I have an button to Browse my Computer and an Open Button that allows me to open the file I have associated on my Computer. The browse button also places the name of the file into a a field named tbFileName on my form. My question is, once I associated this file there is no way to unassociate it on this form. Is there a way to delete this with a delete button? Here is my code. Any help would greatly be appreciated. Thanks. -------------------------------------------------------------------------------------------------- Private Sub bBrowse_Click() On Error GoTo Err_bBrowse_Click Dim strFilter As String Dim lngFlags As Long Dim varFileName As Variant ' strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _ ' & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*" ' strFilter = "Access Files (*.mdb)" & vbNullChar & "*.mdb*" strFilter = "All Files (*.*)" & vbNullChar & "*.*" lngFlags = tscFNPathMustExist Or tscFNFileMustExist Or tscFNHideReadOnly varFileName = tsGetFileFromUser( _ fOpenFile:=True, _ strFilter:=strFilter, _ rlngflags:=lngFlags, _ strDialogTitle:="Find File (Select The File And Click The Open Button)") If IsNull(varFileName) Or varFileName = "" Then Debug.Print "User pressed 'Cancel'." Beep MsgBox "File selection was canceled.", vbInformation Exit Sub Else 'Debug.Print varFileName tbFile = varFileName End If Call ParseFileName Exit_bBrowse_Click: Exit Sub Err_bBrowse_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bBrowse_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub bOpenFile_Click() On Error GoTo Err_bOpen_Click If IsNull(tbFile) Or tbFile = "" Then MsgBox "Please browse and select a valid file to open.", vbCritical, "Invalid File" Else OpenFile (tbFile) End If Exit_bOpen_Click: Exit Sub Err_bOpen_Click: MsgBox Err.Number & " - " & Err.Description Resume Exit_bOpen_Click End Sub ---------------------------------------------------------------------------------------------- Private Sub ParseFileName() On Error GoTo Err_ParseFileName Dim sFullName As String Dim sFilePathOnly As String Dim sDrive As String Dim sPath As String Dim sLocation As String Dim sFileName As String sFullName = tbFile.Value ' Find the final "\" in the path. sPath = sFullName Do While Right$(sPath, 1) "\" sPath = Left$(sPath, Len(sPath) - 1) Loop ' Find the Drive. sDrive = Left$(sFullName, InStr(sFullName, ":") + 1) 'tbDrive = sDrive ' Find the Location. sLocation = Mid$(sPath, Len(sDrive) - 2) 'tbLocation = sLocation ' Find the Path. sPath = Mid$(sPath, Len(sDrive) + 1) 'tbPath = sPath ' Find the file name. sFileName = Mid$(sFullName, Len(sPath) + 4) tbFileName = sFileName Exit_ParseFileName: Exit Sub Err_ParseFileName: MsgBox Err.Number & " - " & Err.Description Resume Exit_ParseFileName End Sub |
Thread Tools | |
Display Modes | |
|
|