Problem with Msgbox Code

O

Old Dog

I have the following code in a project which is responding in a way I
don't understand. Any enlightenment would be appreciated as I am new at
this. When the Cancel button is clicked I get an error code.

Else
MsgBox " There were no files found. ", vbRetryCancel, "Please
Respond"
If Msg = 4 Then
' What to do code
End If
If Msg = 7 Then
Exit Sub
End If

Run-time error '380':
Could not set the List property. Invalid property value.

All I am trying to do is to give the user a opportunity to exit the
procedure.
 
N

Norman Jones

Hi Old Dog,

Try this slight adaptation of your code:

'==========>>
Sub aTester()
Dim Msg As Long
Msg = MsgBox(" There were no files found. ", _
vbRetryCancel, "Please Respond")
If Msg = 4 Then
'User pressed Retry: What to do code
End If
If Msg = 2 Then
MsgBox "You cancelled!"
Exit Sub
End If

End Sub
'<<==========
 
N

Norman Jones

Or, rather:

Sub aTester()
Dim Msg As Long

Msg = MsgBox(" There were no files found. ", _
vbRetryCancel, "Please Respond")

If Msg = 4 Then
'User pressed Retry: What to do code
ElseIf Msg = 2 Then
MsgBox "You cancelled!"
Exit Sub
End If

End Sub
 
O

Old Dog

One followup question:

Once, I Exit this routine which is behind a Userform, the code returns
to the original sub routine with the Userform still on the screen. Is
there away to avoid this and get the last line End Sub to run.

The originating routine has the following code:

Sub FileSearchTest()

FilesSelect1UserForm.Show

End Sub
 

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