Run time error 52

T

Tom

Hi all - Could use some help on this one.

I've got a module and two userforms. When I try to show the second userform
I get an error message of "runtime error '52' bad file name or number" and it highlights
my form2.show command.

When I run the same code on my home machine it works, but on my office machine I get
the error message.

Any suggestions on what can be causing this and how to fix it?

If it helps, here are the two ways I've tried to show the second form based on some previous
posts:

In module
Sub StartMyForm()
Form1.show
End Sub

In Form1
CmdButton1_Click
Displays a dialog box

CmdButton2_Click
Displays another dialog box

CmdButton3_Click
Me.Hide
Function1
Function2
Form2.Show (This is the line highlighted after the error message)

I've also tried this method but got the same error message:
In module
Sub StartMyForm()
Form1.Show
Form2.Show
Unload Form1
Unload Form2
End Sub

Again, both methods worked on my home machine, neither works on the office machine.
Any help would be greatly appreciated.
Thanks in advance.
Tom
 
P

Perry

Could be a lot of reasons.
You'll have to kick in what's programmed in UserForm_Initialize() event of
Form2
for anyone to diagnose.

Krgrds,
Perry
 
T

Tom

Here's what I have Perry. Thanks for taking a look.

Private Sub UserForm_Initialize()

CommandButton1.Caption = "Close "
CommandButton2.Caption = "Open selected"

TextBox1 = myFolder 'contains the folder selected using Dialogs(wdDialogCopyFile) completed in Form1

ListBox1.MultiSelect = fmMultiSelectExtended
ListBox1.ListStyle = fmListStyleOption

ListBox2.MutliSelect = fmMultiSelectSingle
ListBox2.ListStyle = fmListStylePlain

ListBox2.MousePointer = fmMousePointerNoDrop

ListBox1.Clear
sPath = Trim(TextBox1)
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
TextBox1 = sPath

Dim afile
Dim bfile

afile = Dir(sPath & "*.doc")

While afile <> ""
ListBox1.AddItem afile
afile = Dir
Wend

If ListBox1.ListCount = 0 Then
MsgBox "No Doc files found"
End If

ListBox2.Clear
bPath = Trim(TextBox1)
If Right(bPath, 1) <> "\" Then bPath = bPath & "\"
TextBox1 = bPath

bfile = Dir(bPath & "*.rtf")

While bfile <> ""
ListBox2.AddItem bfile
bfile = Dir
Wend
If ListBox2.ListCount = 0 Then
MsgBox "No Doc files found list2"
End If


myShortenPath 'Function in module to return just the name of last folder in path

Label1.Caption = "Contents of:" & Chr(13) & myFolder
Label4.Caption = myFolder

'Display count of .wpd files
Dim j As Long
'Dim strSaveFile As String
With Application.FileSearch
.FileName = "*.wpd"
.LookIn = myFolder
.SearchSubFolders = False
.Execute
'If .FoundFiles.Count > 0 Then
'MsgBox .FoundFiles.Count
'For i = 1 To .FoundFiles.Count
Label2.Caption = .FoundFiles.Count & " file(s) found"
End With

'Display count of .doc files
Dim k As Long
'Dim strSaveFile As String
With Application.FileSearch
.FileName = "*.doc"
.LookIn = myFolder
.SearchSubFolders = False
.Execute
'If .FoundFiles.Count > 0 Then
'MsgBox .FoundFiles.Count
'For i = 1 To .FoundFiles.Count
Label3.Caption = .FoundFiles.Count & " file(s) converted"
End With

End Sub

Here is the myShortenPath function which is in the module
Function myShortenPath()
'Get Name of last folder in path
Dim myPath As String
Dim nSlash As Long

myPath = myFolder

' remove the quotes
myPath = Replace(myPath, """", "")

If Len(myPath) <= 3 Then
' "C:\" or similar, or empty
myFolder = myPath
Else
' if last character is a backslash,
' remove it
If Right(myPath, 1) = "\" Then
myPath = Left(myPath, Len(myPath) - 1)
End If

' find the last remaining backslash
nSlash = InStrRev(myPath, "\")

' extract the substring that follows it
If nSlash > 0 Then
myFolder = Right(myPath, Len(myPath) - nSlash)
End If
End If
End Function
 
P

Perry

Hi Tom,

You'd be better of stepping through your code
by pressing F8 when the debugger kicks in at

form2.show

Click 'Debug' (don't click 'End') in the debugdialog:

This will take you on a step by step code walkthrough
and it will take you exactly to the statement that's causing the headache.

Btw, this is the way to debug yr applications. Step through your code.

Now, if you can't fix the problem you encounter, could you repost
and indicate exactly where the bug is ....

Krgrds,
Perry

Tom said:
Here's what I have Perry. Thanks for taking a look.

Private Sub UserForm_Initialize()

CommandButton1.Caption = "Close "
CommandButton2.Caption = "Open selected"

TextBox1 = myFolder 'contains the folder selected using
Dialogs(wdDialogCopyFile) completed in Form1
 
T

Tom

Hey Perry -

Just wanted to let you know I followed your advice and was able to fix the problem.
Thanks for all your help. It's greatly appreciated.

Tom
 
P

Perry

Out of curiosity:

In short, what was the problem? and how did you solve that?

Krgrds,
Perry
 
Top