Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / August 2006

Tip: Looking for answers? Try searching our database.

Need a Delete Button?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 29 Aug 2006 21:11 GMT
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
ManningFan - 29 Aug 2006 21:44 GMT
You could set tbFile = "", but it looks like you're trapping that as an
error.

> 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
[quoted text clipped - 112 lines]
>
> End Sub
Douglas J. Steele - 29 Aug 2006 22:11 GMT
What do you mean by "unassociate it on this form"? Remove the value from
tbFileName, or something else?

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> 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
[quoted text clipped - 112 lines]
>
> End Sub
Mike - 29 Aug 2006 23:00 GMT
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.

> What do you mean by "unassociate it on this form"? Remove the value from
> tbFileName, or something else?
[quoted text clipped - 120 lines]
> >
> > End Sub
Douglas J. Steele - 30 Aug 2006 00:50 GMT
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.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

>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
[quoted text clipped - 129 lines]
>> >
>> > End Sub
Mike - 30 Aug 2006 01:24 GMT
Perfect! Did not think it would be that easy!!!
Thanks!
Mike

> Sorry, it still doesn't make sense to me.
>
[quoted text clipped - 140 lines]
> >> >
> >> > End Sub
Larry Linson - 30 Aug 2006 01:14 GMT
>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
[quoted text clipped - 4 lines]
>
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.