Hide / Unload Form

J

JayM

I am creating a userform from a macro I have but I need further functionality
and extra buttons so an input box is no longer sufficient.

I have started with the basics but am having trouble unloading or hiding the
form once the OK button is clicked.

See code below. Any help appreciated.

Many thanks

JayM

Code:

Private Sub cmdOK_Click()
' Inserts User Texts
On Error GoTo errhandler
resultx = txtUserText
' InputBox("Please enter the name of the Text Segment you wish to use :",
"Enter Short Text")
If resultx = "" Then Exit Sub
resulty = Dir(varDriveZZword & "USERTEXT\" & resultx & ".DOC",
vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem)
If resulty = "" Then
MsgBox "Sorry, but '" & resultx & "' is NOT a valid Text Segment.
Please Try Again .....", vbCritical, resultx & " : NOT FOUND !"
Exit Sub
End If
Selection.InsertFile FileName:=varDriveZZword & "USERTEXT\" & resultx &
".DOC", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
Exit Sub
errhandler:
MsgBox "Sorry, but '" & resultx & "' is NOT a valid Text Segment.
Please Try Again .....", vbCritical, resultx & " : NOT FOUND !"

frmUserText.Hide

End Sub
 
D

Doug Robbins - Word MVP

For what you have shown, an InputBox should be sufficient.

However See thefollowing page of Greg Maxey's website :

http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
J

JayM

Hi Doug.

Thanks for that. I had actually worked out what I was doing wrong.

With regard to the Input box that is what we are currently using but I now
want to be able to add some extra buttons to go to different locations so the
user can select the text rather than remembering it's name.

However, it would be nice to have the choice so my thinking was to put some
sub folders in where the user could browse to but in the USERTEXT folder have
a shortcut to the sub folders so that the filename could be typed in.

Unfortunately this just results in the error message saying the file doesn't
exist. Do you know if there is a way around this?

JayM
 

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