I have the following code:
I have some totally unrelated code in the same procedure, but it runs fine when this code is commented out. What happens, is that when the user hits the OK button on the form, the message box I have coded above comes up, and the vb code is exited, whether there is data on the form or not. I think it has something to do with my variable for the Controls, b/c that has worked fine in Access VBA, but there must be some other way to do it with Excel, b/c I think it is assuming that I mean for each control on the Excel worksheet, and not for each control on the UserForm. The code is located in the Uswer form module.
Any advice/help here would be greatly appreciated.
Stephen![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
Code:
Private Sub cmdOk_Click()
Dim frm As UserForm
Set frm = frmBatchAudit
Dim ctl As Control
Dim CR As String
CR = Chr$(13)
For Each ctl In frm.Controls
If ctl = vbNullString Then
Else
MsgBox "Please Enter Batch Id's in the" & CR & _
"appropriate fields, or hit <Cancel>" & CR & _
"to exit form."
Exit Sub
End If
Next ctl
End Sub
I have some totally unrelated code in the same procedure, but it runs fine when this code is commented out. What happens, is that when the user hits the OK button on the form, the message box I have coded above comes up, and the vb code is exited, whether there is data on the form or not. I think it has something to do with my variable for the Controls, b/c that has worked fine in Access VBA, but there must be some other way to do it with Excel, b/c I think it is assuming that I mean for each control on the Excel worksheet, and not for each control on the UserForm. The code is located in the Uswer form module.
Any advice/help here would be greatly appreciated.
Stephen
![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV