PDA

View Full Version : Removing Form Focus and Hiding Active Document



specterunsee
08-22-2008, 06:21 AM
I've searched thoroughly, so please don't flame me if I missed a post answering this. I'm new to VBA and have been working on a rpp calculator etc in excel and now a VBA form in word to type my notes that are close the same every single time. I didn't like mail merge as much since its extra steps, wheras my form I type in the text boxes, hit execute and it in the background builds the string, and cuts so I can paste. 2 things I'm having trouble finding, which I've found for excel, but not for word....

1. How do I clear all the boxes: I have:

Private Sub resetFormAndCountCalls_Click()
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
ctl.Text = ""
End If
Next ctl
txtIBCALL.SetFocus
End Sub

Says error: User defined type not defined. This worked a couple times now it doesn't?!

2. How can I allow other documents to execute WHILE the form is up. I would like to use other macros while form is up for documentation

3. How can hide the document while the form is open.

Basic questions, please give me some help. I've googled this stuff over 4 hours.

CreganTur
08-22-2008, 09:36 AM
Welcome to the forums! Always good to see new faces.


I've searched thoroughly, so please don't flame me if I missed a post answering this.
Don't worry about it... actually I don't think I've ever seen anyone flame anyone else on these forums. We try to keep it professional around here:jester:


1. How do I clear all the boxes: I have:
You're almost there with this code (very good job of taking this down to the object level!) You just need to declare what ctl is- the error is because you never declared it.

If you are not using Option Explicit, then you really should... can't stress that enough. Oh, and when posting code please wrap it in the VBA tags- it'll make it easier to read and format it according to VBIDE.

Try this:
Private Sub resetFormAndCountCalls_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
ctl.Text = ""
End If
Next ctl
txtIBCALL.SetFocus
End Sub


I'm not sure how to anwer your other questions right now... but I hope I've helped you with your first question.

NinjaEdithttp://img293.imageshack.us/img293/9060/ninja3od8.gif: MD kindly pointed out an error with the first code I posted. The above code is tested and verified as working.