Need a Delete Button?

M

Mike

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
 
D

Douglas J. Steele

What do you mean by "unassociate it on this form"? Remove the value from
tbFileName, or something else?
 
M

Mike

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.
 
D

Douglas J. Steele

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.
 
L

Larry Linson

Mike said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top