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

IVE GOT A CONFUSING PROBELM- Help needed please

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
Here is the run-down.
FileList1 is on a form named FileList.
I can open files from my file list box, and my common dialog, no problem. After I save a file I CAN NOT open a file from my listbox, but I can still open a file from my common dialog.

MyFile is delared as a Global String in a module.

Here is the code that is executed when a file is opened from the file list box.

Text1.Text = Filelist1.FileName
MyName = Text1.Text
Dim NewOpen As New frmOpenNote
NewOpen.Show

Form NewOpen handles the opening of the selected file (the file selected in FileList1) This is the code.

Me.TxtArea.LoadFile MyName

THIS CODE WORKS PERFECTLY UNTILL YOU SAVE A FILE. When you save a file (using commondialog1) and then you try to open a file using the FileList1, Run-Time error 75 occurs- The specified path/file name cannot be accessed or is invalid. When I click debug, the code that is hilighted is this: Me.TxtArea.LoadFile MyName

After you end the program, run it again, and try to open a file using filelist1, EVEN BEFORE A SAVE, VB returns that error, and the only way for that code to work again is to close VB, and open the project back up, and then it works, and it all starts again. By the way, I have compiled the program, and I ran it, if I save the same error occurs.

WHAT IS GOING ON HERE?!??!?
 
Here is some extra information.

Text1 is on filelist.frm

Me.TxtArea.LoadFile MyName is in the form load event of NewOpen

 
It seems like there may be something weird happening when the file is saved.
I have just tried to recreate your problem, but it worked for me. This is what I have got:

1. Add a form to a project and change its name to FileList.
2. Add a file list box to the form and change its name to FileList1.
3. Add the following code to the form:

Option Explicit

Private Sub FileList1_DblClick()
Text1.Text = FileList1.FileName
MyName = Text1.Text
Dim NewOpen As New frmOpenNote
NewOpen.Show
Set NewOpen = Nothing ' reclaim memory
End Sub

Private Sub Form_Load()
FileList1.Path = "C:\aa\" ' change to your directory
FileList1.Refresh
End Sub


4. Add another form and change its name to frmOpenNote.
5. Add a rich text box control to this form and change its name to TxtArea.
6. Add two buttons and change their names to cmdSave and cmdClose and change their captions to &Save and &Close respectively.
7. Add the following code to the form:

Option Explicit

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdSave_Click()

Dim objComDlg As New CommonDialog
Dim sNewName As String

objComDlg.Flags = cdlOFNExplorer
objComDlg.Filter = "Text Files (*.txt)|*.txt"
objComDlg.CancelError = False
objComDlg.ShowSave
sNewName = objComDlg.FileName

If Len(sNewName & "") = 0 Then
MsgBox "No file name. Could not save.", vbExclamation + vbOKOnly
Else
If Len(Dir$(sNewName)) <> 0 Then
If MsgBox(&quot;File already exists. Do you want to overwrite?&quot;, vbExclamation + vbYesNo) = vbYes Then
TxtArea.SaveFile sNewName
MsgBox &quot;File has been saved&quot;, vbInformation + vbOKOnly
Else

End If
Else
TxtArea.SaveFile sNewName
MsgBox &quot;File has been saved&quot;, vbInformation + vbOKOnly
End If
End If
Set objComDlg = Nothing

End Sub

Private Sub Form_Load()
Me.TxtArea.LoadFile MyName
End Sub


8. Add a BAS module to the project and place the following code inside it:

Option Explicit

Global MyName As String


9. Run the program.

Double click on any of the files in the list (I tested with *.txt files). Edit the file and save, selecting the same path and file name of the file you just double-clicked on. Then you should be able to close frmOpenNote and double click on the same file and it should open and display your changes.

Let me know how you get on with this.

Simon
 
something rather interesting just occured, I opened VB to test your code, and my code worked, no matter what different save scenarios I tried...
 
May be due to your references being in a different order in the references list or a different version of the reference.
 
the showsave method does not re-initialize some properties.

during the save, if you change a drive or directory, the curdir is changed and remains changed. So is the commondialog.filename and commondialog.initdir.

this MIGHT cause a problem when you re-enter the procedure. The error 75 could occur if the commondialog.initdir property is invalid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top