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

Word 2000 list box macro problem 1

Status
Not open for further replies.

jfhewitt

Technical User
Jun 6, 2000
287
US
I have a user Form containing a list box of file names I want inserted into a document. If the user does not select an name from the list, I get a Null error (normal). I want to error trap and remind the user to select the file before pressing OK button. How can I keep the Null error from repeating?
here is my code for the command button on the form:

Private Sub cmdOK_Click()
ChangeFileOpenDirectory ("C:\My Documents")
Dim var As Variant
var = ColorBox.Value
On Error GoTo ErrorHandler
ErrorHandler:

MsgBox "Enter one selection, OK?", vbExclamation

Selection.InsertFile FileName:=var
End Sub

Any ideas? I would think is pretty basic. I think my problem is how to get out of ErrorHandler and back to the macro.
 

Private Sub cmdOK_Click()
On Error GoTo ErrorHandler
ChangeFileOpenDirectory ("C:\My Documents")
Dim var As Variant
var = ColorBox.Value

[red]create an IF/ENDIF to verify that ListIndex is not null. If it is null then do the MSGBOX, then listbox.setfocus, and exit sub[/red]

Selection.InsertFile FileName:=var

ErrorHandler:
MsgBox "Enter one selection, OK?", vbExclamation

End Sub

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Thanks...that did it. For list boxes, this seems a simply method than the On Error statement.
 

Glad to have helped.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top