A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

If...Then Code not working



 
 
Thread Tools Display Modes
  #1  
Old January 4th, 2010, 12:34 AM posted to microsoft.public.access.forms
Pamela
external usenet poster
 
Posts: 193
Default If...Then Code not working

I have a cbo on my form and I want it to be that if the user tries to skip
it, a message box opens instructing the user to enter "None" as opposed to
just leaving it blank and so return focus to that cbo for that entry. I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter ""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela
  #2  
Old January 4th, 2010, 12:50 AM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default If...Then Code not working

Instead of:

If Me.ShopName = Null Then

try:

If Len(Me.ShopName & vbNullString) = 0 Then

Even better, why bother making them enter "None"? Just do it for them. So
I'd do this:

If MsgBox("Are you sure there's no shop?", vbYesNo, "Enter Shop") = vbYes
Then
Me.ShopName = "None"
Else
Me.ShopName.SetFocus
End If

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Pamela" wrote in message
...
I have a cbo on my form and I want it to be that if the user tries to skip
it, a message box opens instructing the user to enter "None" as opposed to
just leaving it blank and so return focus to that cbo for that entry. I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter
""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela



  #3  
Old January 4th, 2010, 12:58 AM posted to microsoft.public.access.forms
Gina Whipp
external usenet poster
 
Posts: 3,500
Default If...Then Code not working

Hmmm, thinking out loud here... Suppose the End-User goes right past that
field and never stops there? You could set the Default Value as 'None" and
then if they do pass it by at least it's not blank. And then put a message
letting them know the Shop is None before proceeding to the next record.
Not sure what your forms are like so not sure where to tell you to put the
message...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"Arvin Meyer [MVP]" wrote in message
...
Instead of:

If Me.ShopName = Null Then

try:

If Len(Me.ShopName & vbNullString) = 0 Then

Even better, why bother making them enter "None"? Just do it for them. So
I'd do this:

If MsgBox("Are you sure there's no shop?", vbYesNo, "Enter Shop") = vbYes
Then
Me.ShopName = "None"
Else
Me.ShopName.SetFocus
End If

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Pamela" wrote in message
...
I have a cbo on my form and I want it to be that if the user tries to skip
it, a message box opens instructing the user to enter "None" as opposed
to
just leaving it blank and so return focus to that cbo for that entry. I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter
""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela





  #4  
Old January 4th, 2010, 01:43 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default If...Then Code not working

On Sun, 3 Jan 2010 16:34:01 -0800, Pamela
wrote:

I have a cbo on my form and I want it to be that if the user tries to skip
it, a message box opens instructing the user to enter "None" as opposed to
just leaving it blank and so return focus to that cbo for that entry. I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter ""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela


The Exit event will fire *only* if the user enters the ShopName control in the
first place, and then goes somewhere else. It won't fire if the user simply
skips over this control.

The Form's BeforeUpdate event is your best bet for making the user enter
required fields:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Len(Me!ShopName & "") = 0 Then
MsgBox "Please select a value for ShopName", vbOKOnly
Me.ShopName.SetFocus
Cancel = True
End If
End Sub

If "None" is an appropriate default... then by all means make it the default,
rather than forcing your user to type it!
--

John W. Vinson [MVP]
  #5  
Old January 4th, 2010, 02:12 AM posted to microsoft.public.access.forms
Pamela
external usenet poster
 
Posts: 193
Default If...Then Code not working

That is wonderful!! I think that's the hardest part about being so green in
Access -- I don't even know the possibilities! It makes perfect sense and
is a great answer but the possibility just escaped me. Thank you, Thank you!!

Pamela

"Arvin Meyer [MVP]" wrote:

Instead of:

If Me.ShopName = Null Then

try:

If Len(Me.ShopName & vbNullString) = 0 Then

Even better, why bother making them enter "None"? Just do it for them. So
I'd do this:

If MsgBox("Are you sure there's no shop?", vbYesNo, "Enter Shop") = vbYes
Then
Me.ShopName = "None"
Else
Me.ShopName.SetFocus
End If

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Pamela" wrote in message
...
I have a cbo on my form and I want it to be that if the user tries to skip
it, a message box opens instructing the user to enter "None" as opposed to
just leaving it blank and so return focus to that cbo for that entry. I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter
""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela



.

  #6  
Old January 4th, 2010, 03:46 PM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default If...Then Code not working

That because I didn't mention that:

If Len(Me.ShopName & vbNullString) = 0 Then

should be used in the form's BeforeUpdate event.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Gina Whipp" wrote in message
...
Hmmm, thinking out loud here... Suppose the End-User goes right past that
field and never stops there? You could set the Default Value as 'None"
and then if they do pass it by at least it's not blank. And then put a
message letting them know the Shop is None before proceeding to the next
record. Not sure what your forms are like so not sure where to tell you to
put the message...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"Arvin Meyer [MVP]" wrote in message
...
Instead of:

If Me.ShopName = Null Then

try:

If Len(Me.ShopName & vbNullString) = 0 Then

Even better, why bother making them enter "None"? Just do it for them. So
I'd do this:

If MsgBox("Are you sure there's no shop?", vbYesNo, "Enter Shop") = vbYes
Then
Me.ShopName = "None"
Else
Me.ShopName.SetFocus
End If

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Pamela" wrote in message
...
I have a cbo on my form and I want it to be that if the user tries to
skip
it, a message box opens instructing the user to enter "None" as opposed
to
just leaving it blank and so return focus to that cbo for that entry. I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter
""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela







  #7  
Old January 4th, 2010, 05:22 PM posted to microsoft.public.access.forms
Gina Whipp
external usenet poster
 
Posts: 3,500
Default If...Then Code not working

Arvin,

Wasn't *picking* on you was just thinking out loud...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

"Arvin Meyer [MVP]" wrote in message
...
That because I didn't mention that:

If Len(Me.ShopName & vbNullString) = 0 Then

should be used in the form's BeforeUpdate event.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Gina Whipp" wrote in message
...
Hmmm, thinking out loud here... Suppose the End-User goes right past that
field and never stops there? You could set the Default Value as 'None"
and then if they do pass it by at least it's not blank. And then put a
message letting them know the Shop is None before proceeding to the next
record. Not sure what your forms are like so not sure where to tell you
to put the message...

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" -
Tremors II

http://www.regina-whipp.com/index_files/TipList.htm

"Arvin Meyer [MVP]" wrote in message
...
Instead of:

If Me.ShopName = Null Then

try:

If Len(Me.ShopName & vbNullString) = 0 Then

Even better, why bother making them enter "None"? Just do it for them.
So I'd do this:

If MsgBox("Are you sure there's no shop?", vbYesNo, "Enter Shop") =
vbYes Then
Me.ShopName = "None"
Else
Me.ShopName.SetFocus
End If

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


"Pamela" wrote in message
...
I have a cbo on my form and I want it to be that if the user tries to
skip
it, a message box opens instructing the user to enter "None" as opposed
to
just leaving it blank and so return focus to that cbo for that entry.
I
don't get an error on my code, but I don't get the message box either.
Here's my code:
Private Sub ShopName_Exit(Cancel As Integer)
If Me.ShopName = Null Then
MsgBox ("Please make a selection from the list." & vbCrLf & "Enter
""None""
if the owner has not chosen a shop.")
Me.ShopName.SetFocus
End If
End Sub
Thanks so much!
Pamela








 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.