For...Next Satement with a UserForm

C

Charles

I have a UserForm which is used to update a document and print two copies.
The user enters the number of docs to complete in a TexBox TxtCnt.

The For.. Next Statement works but control does not return to the UserForm
after printing. How do i do that?

This is a simplified version of the code (I have removed a lot of repetitive
lines):

Private Sub cmdOK_Click()
Dim strReason As String
Dim strType As String
Dim i As Integer
For i = 1 To TxtCnt.Value

If optReason1 = True Then strReason = "Actual Exit"
If optType1 = True Then strType = "Leaving Service"

Application.ScreenUpdating = False

UpdateBookmark "bmkID", txtID.Value
UpdateBookmark "bmkSur", txtSur.Value

Application.ScreenUpdating = True
ActiveDocument.PrintOut Copies:=2

optReason1.Value = True
optType1.Value = True
txtID.Value = Null
txtSur.Value = Null

Application.ScreenUpdating = True

Next i

End Sub

Thanks for any help you can offer.
 
J

Jean-Guy Marcil

Charles was telling us:
Charles nous racontait que :
I have a UserForm which is used to update a document and print two
copies. The user enters the number of docs to complete in a TexBox
TxtCnt.

The For.. Next Statement works but control does not return to the
UserForm after printing. How do i do that?

This is a simplified version of the code (I have removed a lot of
repetitive lines):

Private Sub cmdOK_Click()
Dim strReason As String
Dim strType As String
Dim i As Integer
For i = 1 To TxtCnt.Value

If optReason1 = True Then strReason = "Actual Exit"
If optType1 = True Then strType = "Leaving Service"

Application.ScreenUpdating = False

UpdateBookmark "bmkID", txtID.Value
UpdateBookmark "bmkSur", txtSur.Value

Application.ScreenUpdating = True
ActiveDocument.PrintOut Copies:=2

optReason1.Value = True
optType1.Value = True
txtID.Value = Null
txtSur.Value = Null

Application.ScreenUpdating = True

Next i

End Sub

Thanks for any help you can offer.

You could hide it before launching the procedure and the Show it again
after.

Private Sub cmdOK_Click()
Dim strReason As String
Dim strType As String
Dim i As Integer

Me.Hide

For i = 1 To TxtCnt.Value
'Your code...
Next i

Me.Show

End Sub


Does that help?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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