Good evening all - my inexperience with VBA is again showing and despite many many google searches I just can't seem to get the code below to work, Please could someone point me in the right direction or let me know what I've got wrong.
So the 'CkbAncestors_Click' works fine, the first issue I'm having is setting the focus back to 'TextboxAncestors' if a users clicks yes on the msgbox but the BackColour changes.
The next issue is with the 'Else', again the BackColor bit works ok but thats all that works in that 'block'
Basically what I'm trying to achieve is if a user ticks the checkbox the focus goes to the associated textbox but if the user leaves the textbox empty when they exit it they are prompted with a yes/no msgbox to let them know. If they select yes then the focus is sent back to the textbox for them to enter a number. If they choose no then the checkbox loses it tick, the textbox get a value of 0 and the BackColor goes back to white.
Just in case its important to know I have 47 versions of the above on the form and the Tabstop property is set to false on all of them when the Userform opens,
Hopefully some of the above makes some sense but more than happy to answer any questions if needbe.
Many thanks in anticipation
Paul
VBA Code:
Private Sub CkbAncestors_Click()
If CkbAncestors.Value = True Then
TextboxAncestors.Enabled = True
TextboxAncestors.SetFocus
TextboxAncestors.Text = ""
TextboxAncestors.BackColor = RGB(204, 255, 255)
Else
TextboxAncestors.BackColor = RGB(255, 255, 255)
End If
End Sub
VBA Code:
Private Sub TextboxAncestors_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CkbAncestors.Value = True And Trim(TextboxAncestors.Value) = "" Then
TextboxAncestors.BackColor = RGB(255, 255, 255)
MsgBox "It looks like you've not entered the number of bottles sold." & vbCrLf & vbCrLf & _
"Do you want to enter a number?", vbYesNo, "Quantity Required"
If vbYes Then
Me.TextboxAncestors.SetFocus
Me.TextboxAncestors.BackColor = RGB(204, 255, 255)
Else
CkbAncestors.Value = False
Me.TextboxAncestors.Text = "0"
Me.TextboxAncestors.BackColor = RGB(255, 255, 255)
End If
End If
End Sub
So the 'CkbAncestors_Click' works fine, the first issue I'm having is setting the focus back to 'TextboxAncestors' if a users clicks yes on the msgbox but the BackColour changes.
The next issue is with the 'Else', again the BackColor bit works ok but thats all that works in that 'block'
Basically what I'm trying to achieve is if a user ticks the checkbox the focus goes to the associated textbox but if the user leaves the textbox empty when they exit it they are prompted with a yes/no msgbox to let them know. If they select yes then the focus is sent back to the textbox for them to enter a number. If they choose no then the checkbox loses it tick, the textbox get a value of 0 and the BackColor goes back to white.
Just in case its important to know I have 47 versions of the above on the form and the Tabstop property is set to false on all of them when the Userform opens,
Hopefully some of the above makes some sense but more than happy to answer any questions if needbe.
Many thanks in anticipation
Paul