PC Review


Reply
Thread Tools Rate Thread

Can program go back to userform to give user another go at it?

 
 
salgud
Guest
Posts: n/a
 
      7th Apr 2009
I'm trying to do something that seems simple but I can't get it to do what
I want. I query the user for 3 pieces of information using 3 comboxes. The
userform code for the "Enter" button to capture the data is:

Private Sub cbEnter_Click()
sTribeNameUI = frmTribeNameSMCY.cbTribeName.Text
sCYUI = frmTribeNameSMCY.cbCY
sServMonthUI = frmTribeNameSMCY.cbServMonth


If sTribeNameUI = "" Or sCYUI = "" Or sServMonthUI = "" _
Or sCYUI = "" Then
MsgBox "Please select a Tribe Name, a Service Month and" & Chr(10) & _
" a Calendar Year!", vbOKOnly
With Me.cbTribeName
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Me.Hide
End If

End Sub

The subroutine that calls the userform is:

Public Sub TribeNameServDate()
Application.ScreenUpdating = True
frmFacil.Hide
frmTribeNameSMCY.Show
Application.ScreenUpdating = False

Unload frmTribeNameSMCY

ws.Range("A1").Value = sTribeNameUI & " Turnaround Report"

ws.Range("D3").Value = sServMonthUI

iServMonth = Month(DateValue(ws.Range("d3") & " 1,2009"))

iPayrollMonth = iServMonth + 1

If iPayrollMonth > 12 Then
iPayrollMonth = iPayrollMonth - 12
End If

sPayrollMonth = Format(28 * iPayrollMonth, "MMM") 'converts integer month
to text month
ws.Range("C3").Value = sPayrollMonth

If iPayrollMonth < 6 Then
sSFY = Right(sCYUI, 2)
Else
sSFY = Right(sCYUI + 1, 2)
End If

ws.Range("J3:K3").Select
Selection.NumberFormat = "@"
ws.Range("J3") = Right(sCYUI, 2)
ws.Range("K3") = sSFY
ws.Range("A1").Select

End Sub

But this stops after the message box warns the user they haven't entered at
least one of the required pieces of data. I want to return them to the
userform to give them another change to fill it in. Does anyone see how I
can modify this code, either in the userform or the other sub, or both, to
get the program to return to the userform, ready to continue with the
program, if they fail to enter the requisite data?
Thanks!
 
Reply With Quote
 
 
 
 
hooksie2@hotmail.com
Guest
Posts: n/a
 
      7th Apr 2009
What about putting the msgbox code into a While loop and move the
Me.Hide to outside the loop, eg

While sTribeNameUI = "" Or sCYUI = "" Or sServMonthUI = "" _
Or sCYUI = ""
MsgBox "Please select a Tribe Name, a Service Month and" & Chr(10) &
_
" a Calendar Year!", vbOKOnly
With Me.cbTribeName
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Wend

me.Hide

You may want to give the user and option to cancel and exit

Cheers,
Andrew
 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      7th Apr 2009
Hi

You don't want to hide the userform if user still need to enter data:

Look at this:

--- cut ---
If sTribeNameUI = "" Or sCYUI = "" Or sServMonthUI = "" _
Or sCYUI = "" Then
MsgBox "Please select a Tribe Name, a Service Month and" & Chr(10) & _
" a Calendar Year!", vbOKOnly
With Me.cbTribeName
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Else
Me.Hide
End If

End Sub

Regards,
Per

"salgud" <(E-Mail Removed)> skrev i meddelelsen
news:19zrnfn56lbt4.122ckawnpe3oy$.(E-Mail Removed)...
> I'm trying to do something that seems simple but I can't get it to do what
> I want. I query the user for 3 pieces of information using 3 comboxes. The
> userform code for the "Enter" button to capture the data is:
>
> Private Sub cbEnter_Click()
> sTribeNameUI = frmTribeNameSMCY.cbTribeName.Text
> sCYUI = frmTribeNameSMCY.cbCY
> sServMonthUI = frmTribeNameSMCY.cbServMonth
>
>
> If sTribeNameUI = "" Or sCYUI = "" Or sServMonthUI = "" _
> Or sCYUI = "" Then
> MsgBox "Please select a Tribe Name, a Service Month and" & Chr(10) & _
> " a Calendar Year!", vbOKOnly
> With Me.cbTribeName
> .SelStart = 0
> .SelLength = Len(.Text)
> .SetFocus
> End With
> Me.Hide
> End If
>
> End Sub
>
> The subroutine that calls the userform is:
>
> Public Sub TribeNameServDate()
> Application.ScreenUpdating = True
> frmFacil.Hide
> frmTribeNameSMCY.Show
> Application.ScreenUpdating = False
>
> Unload frmTribeNameSMCY
>
> ws.Range("A1").Value = sTribeNameUI & " Turnaround Report"
>
> ws.Range("D3").Value = sServMonthUI
>
> iServMonth = Month(DateValue(ws.Range("d3") & " 1,2009"))
>
> iPayrollMonth = iServMonth + 1
>
> If iPayrollMonth > 12 Then
> iPayrollMonth = iPayrollMonth - 12
> End If
>
> sPayrollMonth = Format(28 * iPayrollMonth, "MMM") 'converts integer month
> to text month
> ws.Range("C3").Value = sPayrollMonth
>
> If iPayrollMonth < 6 Then
> sSFY = Right(sCYUI, 2)
> Else
> sSFY = Right(sCYUI + 1, 2)
> End If
>
> ws.Range("J3:K3").Select
> Selection.NumberFormat = "@"
> ws.Range("J3") = Right(sCYUI, 2)
> ws.Range("K3") = sSFY
> ws.Range("A1").Select
>
> End Sub
>
> But this stops after the message box warns the user they haven't entered
> at
> least one of the required pieces of data. I want to return them to the
> userform to give them another change to fill it in. Does anyone see how I
> can modify this code, either in the userform or the other sub, or both, to
> get the program to return to the userform, ready to continue with the
> program, if they fail to enter the requisite data?
> Thanks!


 
Reply With Quote
 
hooksie2@hotmail.com
Guest
Posts: n/a
 
      7th Apr 2009
You're right - no need for the loop in this context - another case of
typing faster than my brain.
 
Reply With Quote
 
salgud
Guest
Posts: n/a
 
      7th Apr 2009
On Tue, 7 Apr 2009 17:09:34 +0200, Per Jessen wrote:

> Hi
>
> You don't want to hide the userform if user still need to enter data:
>
> Look at this:
>
> --- cut ---
> If sTribeNameUI = "" Or sCYUI = "" Or sServMonthUI = "" _
> Or sCYUI = "" Then
> MsgBox "Please select a Tribe Name, a Service Month and" & Chr(10) & _
> " a Calendar Year!", vbOKOnly
> With Me.cbTribeName
> .SelStart = 0
> .SelLength = Len(.Text)
> .SetFocus
> End With
> Else
> Me.Hide
> End If
>
> End Sub
>
> Regards,
> Per
>
> "salgud" <(E-Mail Removed)> skrev i meddelelsen
> news:19zrnfn56lbt4.122ckawnpe3oy$.(E-Mail Removed)...
>> I'm trying to do something that seems simple but I can't get it to do what
>> I want. I query the user for 3 pieces of information using 3 comboxes. The
>> userform code for the "Enter" button to capture the data is:
>>
>> Private Sub cbEnter_Click()
>> sTribeNameUI = frmTribeNameSMCY.cbTribeName.Text
>> sCYUI = frmTribeNameSMCY.cbCY
>> sServMonthUI = frmTribeNameSMCY.cbServMonth
>>
>>
>> If sTribeNameUI = "" Or sCYUI = "" Or sServMonthUI = "" _
>> Or sCYUI = "" Then
>> MsgBox "Please select a Tribe Name, a Service Month and" & Chr(10) & _
>> " a Calendar Year!", vbOKOnly
>> With Me.cbTribeName
>> .SelStart = 0
>> .SelLength = Len(.Text)
>> .SetFocus
>> End With
>> Me.Hide
>> End If
>>
>> End Sub
>>
>> The subroutine that calls the userform is:
>>
>> Public Sub TribeNameServDate()
>> Application.ScreenUpdating = True
>> frmFacil.Hide
>> frmTribeNameSMCY.Show
>> Application.ScreenUpdating = False
>>
>> Unload frmTribeNameSMCY
>>
>> ws.Range("A1").Value = sTribeNameUI & " Turnaround Report"
>>
>> ws.Range("D3").Value = sServMonthUI
>>
>> iServMonth = Month(DateValue(ws.Range("d3") & " 1,2009"))
>>
>> iPayrollMonth = iServMonth + 1
>>
>> If iPayrollMonth > 12 Then
>> iPayrollMonth = iPayrollMonth - 12
>> End If
>>
>> sPayrollMonth = Format(28 * iPayrollMonth, "MMM") 'converts integer month
>> to text month
>> ws.Range("C3").Value = sPayrollMonth
>>
>> If iPayrollMonth < 6 Then
>> sSFY = Right(sCYUI, 2)
>> Else
>> sSFY = Right(sCYUI + 1, 2)
>> End If
>>
>> ws.Range("J3:K3").Select
>> Selection.NumberFormat = "@"
>> ws.Range("J3") = Right(sCYUI, 2)
>> ws.Range("K3") = sSFY
>> ws.Range("A1").Select
>>
>> End Sub
>>
>> But this stops after the message box warns the user they haven't entered
>> at
>> least one of the required pieces of data. I want to return them to the
>> userform to give them another change to fill it in. Does anyone see how I
>> can modify this code, either in the userform or the other sub, or both, to
>> get the program to return to the userform, ready to continue with the
>> program, if they fail to enter the requisite data?
>> Thanks!


Thank you both, problem solved. Now I can take this item off my desk and
move on.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Complete program that give exception ObjectDisposed was unhandled by user Tony Johansson Microsoft C# .NET 1 1st Apr 2010 04:56 AM
Show userform but don't give focus dave.cuthill@computalog.com Microsoft Powerpoint 1 6th Mar 2007 06:59 PM
Give me my DOS back! =?Utf-8?B?TWlrZQ==?= Windows XP General 14 13th Oct 2006 08:23 PM
Give restricted user, admin rights to 1 program? =?Utf-8?B?Q291cnRuZXkgUg==?= Windows XP Security 4 13th Dec 2005 02:57 AM
Statement to give focus to a specific control on a UserForm? Fred Holmes Microsoft Excel Programming 3 20th Dec 2004 07:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:35 AM.