Reputation: 75
After I click send, the textbox that is not filled turns red.
After the popped up message to continue I click yes.
I am unable to continue to fill in the blanks and the email is sent.
Private Sub Send_Click()
'Check the value if blank
If Branchname.Value = "" Or _
subject.Value = "" Or _
Makername.Value = "" Or _
Checkername.Value = "" Or _
Filename.Value = "" Then
'If value=0 then change the highlight to notify user
If Branchname.Value = "" Then
Branchname.BackColor = vbRed
End If
If subject.Value = "" Then
subject.BackColor = vbRed
End If
If Makername.Value = "" Then
Makername.BackColor = vbRed
End If
If Checkername.Value = "" Then
Checkername.BackColor = vbRed
End If
If Filename.Value = "" Then
Filename.BackColor = vbRed
End If
'Display msgbox to prompt user
If MsgBox("Form is not complete.Do you want to continue?", vbQuestion + vbYesNo) <> vbYes Then
Exit Sub
End If
End If
'Call emailfunction
Call Sendbasicemaillatebingding
'reset everything
Call Resetform
'drop the form
Unload Me
End Sub
Upvotes: 0
Views: 73
Reputation: 6165
Because that's what you are telling it to do. The way your code is set up, if you click "No" in the MsgBox
, you exit the Send function and go back to the form. If you click "Yes," you continue execution, calling your send email function, calling a reset form function, and then unloading the form.
Now, when you ask the user "Do you want to continue?" you're asking if the user wants to send the email without completing the form. If the user says yes, then you continue sending the email. If no, then you go back to the form, with the incomplete boxes highlighted in red. Again, that's what your code does. If that isn't what you want to do, then you need to work out what you do want to do and implement it.
Also, there's no logical reason to reset a form and then unload it. Unloading it removes it from the screen. So, it looks like you have to work out the logic of your program flow. Presumably, you want to reset the form and keep it open. Unload the form from some sort of "Exit" button that's next to your "Send" button.
Upvotes: 1