vbYesNo Popup If Field is null or not in list

roystreet

Registered User.
Local time
Today, 13:53
Joined
Aug 16, 2004
Messages
47
Hello,
I am trying to figure out how to use a vbYesNo msg box to open up if a specific field is left null. Field name: cbo_Status. It is a dropdown menu. If it is left null, then the popup will open offering to insert a value for them which would be "Working" or they could press no and it place them back into that field. (I had one that was some-what succesful in my attempt, but for one it still opened the standard access 'not in list' type of error box. I didn't like how it worked anyway, so I want to start afresh this time)
Part two of this is question is that this being a drop down menu I also want to limit the values they can insert into the field. I have it set to value list and set it to limit to list. Example of the values I have in there are: "Project Complete";"Working";"On-Hold";"Not Started" Those are just a few.


Thanks,
---roystreet
 
Roy,

How about setting the DefaultValue to "Working"?

Then, if they don't do anything, you don't.

Otherwise, you could make them go to it (.SetFocus) and using the
LostFocus event, you could "grill" them and find out if they want
to set it to "Working".

Wayne
 
WayneRyan,
Thank you for your reply. I'm slightly confused by what you said, but I do understand that a default value could be 'valuable' here :D, but part of why I ask is for future use with the msg boxes when it comes to using vbYesNo. I've used the boxes before, but only with the OK and not Yes/No. So I wanted to learn how to use that more and this was a good opportunity to use it. This concept could be used in some other areas of this database (or other databases) where maybe I don't/can't put a default value because of the nature of it - Even in this situation I actually don't want the user to 'miss' (overlook) this field and just accept 'Working' as default when they might not be working it, now that I think about it.

Thanks,
---roystreet
 
Last edited:
Another Attempt At This....

Here's my latest attempt at this:
In the form, I'm first going to try working with if it's null, then later I'll attempt to work with Not In List.
Code:
Private Sub cbo_Status_LostFocus()
 If IsNull(cbo_Status) Then
 Call Navigation.emptyplace(Me)
 End If

Now the code in the mod:
Code:
Public Function emptyplace(frm As Form) As Integer
Dim msg, button, title, response
msg = "You did not enter in a value, would you like us to enter Working for you?"
button = vbYesNo + vbDefaultButton2
title = "Missing Current Status"

response = MsgBox(msg, button, title)
If response = vbYes Then
   DoCmd.GoToControl "txtTopic"
   cbo_Status = "Working"
Else
   DoCmd.GoToControl "cbo_status"
End If
End Function

Now, I'm trying to have it enter in the value 'Working' in here. I know the field name is right - I even made an onclick event for some text I had that would put a value in the cbo_status field and it worked just fine. (I wanted to test everything I could think of) If I select yes, it will move to the control 'txtTopic' as it states above, but will leave no value in the cbo_status field. If I click no then the it will just go on to the next field leaving cbo_status? Not sure why it's working this way.

Thanks,
---roystreet
 
If msgbox("You did not enter in a value, would you like us to enter Working for you", vbyesno, "Missing Current Status") = vbyes Then

DoCmd.GoToControl "txtTopic"
cbo_Status = "Working"
Else
DoCmd.GoToControl "cbo_status"
End If

Something like that.
 
Your function will return an integer representing the answer they choose..



Constant Value
vbOK 1
vbCancel 2
vbAbort 3
vbRetry 4
vbIgnore 5
vbYes 6
vbNo 7

Change your module to look like this

Code:
Public Function Emptyplace() As Integer
Dim msg, button, title, response
msg = "You did not enter in a value, would you like us to enter Working for you?"
button = vbYesNo + vbDefaultButton2
title = "Missing Current Status"
emptyplace = MsgBox(msg, button, title)
End Function

So you could change your stuff to use it better...

Code:
Private Sub cbo_Status_LostFocus()
Dim TheAnswer as integer 
If IsNull(cbo_Status) Then
 TheAnswer = Navigation.emptyplace(Me)

If theAnswer = 6 then 'If they hit YES
     'Do something for yes
     txtTopic.SetFocus
elseif theAnswer = 7 then 'If they hit NO
     'Do something for no
     cbo_status.SetFocus
     cbo_status.Text = "Working"
     txtTopic.SetFocus
End If
 
Last edited:

Users who are viewing this thread

Back
Top Bottom