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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
If Statement w/ And and Msgbox Nested
I am getting a syntax error on this code. The code is intended to check that
the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela |
#2
|
|||
|
|||
If Statement w/ And and Msgbox Nested
Pamela
If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela |
#3
|
|||
|
|||
If Statement w/ And and Msgbox Nested
Hi Jeff,
I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . |
#4
|
|||
|
|||
If Statement w/ And and Msgbox Nested
On Mon, 4 Jan 2010 17:38:01 -0800, Pamela
wrote: I think the problem may be with the first line: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then Currently this line means: if there are any remarks and cbFOLConsistent = 2 then... Is that what you meant? Set a breakpoint on the first line, re-run the code, and step through, carefully inspecting the various values (either by hovering over the variable name, or by using other debugging windows, or by entering something like: ?Me.Remarks or ?Len(remarks & vbNullString) in the immediate window. I bet you some values are not what you expected them to be. -Tom. Microsoft Access MVP Hi Jeff, I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . |
#5
|
|||
|
|||
If Statement w/ And and Msgbox Nested
Thanks for bringing that to my attention. I just try to copy code and mix it
in where and how I think I need it but I can't say I necessarily really understand how it all works and what it all means. Any suggestions on how to write the first line so that if Remarks is empty/null (is blank) AND FOLConsistent is 2 that the msgbox then opens?? It makes sense that it isn't working based on your synopsis of the first line. Thanks so much! Pamela "Tom van Stiphout" wrote: On Mon, 4 Jan 2010 17:38:01 -0800, Pamela wrote: I think the problem may be with the first line: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then Currently this line means: if there are any remarks and cbFOLConsistent = 2 then... Is that what you meant? Set a breakpoint on the first line, re-run the code, and step through, carefully inspecting the various values (either by hovering over the variable name, or by using other debugging windows, or by entering something like: ?Me.Remarks or ?Len(remarks & vbNullString) in the immediate window. I bet you some values are not what you expected them to be. -Tom. Microsoft Access MVP Hi Jeff, I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . . |
#6
|
|||
|
|||
If Statement w/ And and Msgbox Nested
On Mon, 4 Jan 2010 19:16:03 -0800, Pamela
wrote: Any suggestions on how to write the first line so that if Remarks is empty/null (is blank) AND FOLConsistent is 2 that the msgbox then opens?? Make it If Len(Me.Remarks & vbNullString)=0 And Me.Parent!cbFOLConsistent = "2" Then This will explicitly check that Remarks is empty. -- John W. Vinson [MVP] |
#7
|
|||
|
|||
If Statement w/ And and Msgbox Nested
After some trial and error, I got it....thanks though!
Here's what worked: If IsNull(Me.Remarks) And (Me.Parent!cbFOLConsistent = "2") Then If MsgBox("If the Facts of Loss are not consistent with the damage, an explanation must be made in Remarks") = vbOK Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If "Tom van Stiphout" wrote: On Mon, 4 Jan 2010 17:38:01 -0800, Pamela wrote: I think the problem may be with the first line: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then Currently this line means: if there are any remarks and cbFOLConsistent = 2 then... Is that what you meant? Set a breakpoint on the first line, re-run the code, and step through, carefully inspecting the various values (either by hovering over the variable name, or by using other debugging windows, or by entering something like: ?Me.Remarks or ?Len(remarks & vbNullString) in the immediate window. I bet you some values are not what you expected them to be. -Tom. Microsoft Access MVP Hi Jeff, I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . . |
#8
|
|||
|
|||
If Statement w/ And and Msgbox Nested
Be careful if your tables allow a null string "" in the remarks field
if me.remarks has "" in it, your IF IsNull will not work as you expect. You can set that in your table design to not allow null string. "Pamela" wrote in message ... After some trial and error, I got it....thanks though! Here's what worked: If IsNull(Me.Remarks) And (Me.Parent!cbFOLConsistent = "2") Then If MsgBox("If the Facts of Loss are not consistent with the damage, an explanation must be made in Remarks") = vbOK Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If "Tom van Stiphout" wrote: On Mon, 4 Jan 2010 17:38:01 -0800, Pamela wrote: I think the problem may be with the first line: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then Currently this line means: if there are any remarks and cbFOLConsistent = 2 then... Is that what you meant? Set a breakpoint on the first line, re-run the code, and step through, carefully inspecting the various values (either by hovering over the variable name, or by using other debugging windows, or by entering something like: ?Me.Remarks or ?Len(remarks & vbNullString) in the immediate window. I bet you some values are not what you expected them to be. -Tom. Microsoft Access MVP Hi Jeff, I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . . |
#9
|
|||
|
|||
If Statement w/ And and Msgbox Nested
Or use
If Len(Me.Remarks & vbNullString) = 0 And (Me.Parent!cbFOLConsistent = "2") Then That will work whether or not zero-length strings are allowed. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chegu Tom" wrote in message ... Be careful if your tables allow a null string "" in the remarks field if me.remarks has "" in it, your IF IsNull will not work as you expect. You can set that in your table design to not allow null string. "Pamela" wrote in message ... After some trial and error, I got it....thanks though! Here's what worked: If IsNull(Me.Remarks) And (Me.Parent!cbFOLConsistent = "2") Then If MsgBox("If the Facts of Loss are not consistent with the damage, an explanation must be made in Remarks") = vbOK Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If "Tom van Stiphout" wrote: On Mon, 4 Jan 2010 17:38:01 -0800, Pamela wrote: I think the problem may be with the first line: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then Currently this line means: if there are any remarks and cbFOLConsistent = 2 then... Is that what you meant? Set a breakpoint on the first line, re-run the code, and step through, carefully inspecting the various values (either by hovering over the variable name, or by using other debugging windows, or by entering something like: ?Me.Remarks or ?Len(remarks & vbNullString) in the immediate window. I bet you some values are not what you expected them to be. -Tom. Microsoft Access MVP Hi Jeff, I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . . |
#10
|
|||
|
|||
If Statement w/ And and Msgbox Nested
Hmm. May want parentheses in there. To avoid the line-wrap problem, let's
try: If (Len(Me.Remarks & vbNullString) = 0) And _ (Me.Parent!cbFOLConsistent = "2") Then -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Douglas J. Steele" wrote in message ... Or use If Len(Me.Remarks & vbNullString) = 0 And (Me.Parent!cbFOLConsistent = "2") Then That will work whether or not zero-length strings are allowed. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chegu Tom" wrote in message ... Be careful if your tables allow a null string "" in the remarks field if me.remarks has "" in it, your IF IsNull will not work as you expect. You can set that in your table design to not allow null string. "Pamela" wrote in message ... After some trial and error, I got it....thanks though! Here's what worked: If IsNull(Me.Remarks) And (Me.Parent!cbFOLConsistent = "2") Then If MsgBox("If the Facts of Loss are not consistent with the damage, an explanation must be made in Remarks") = vbOK Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If "Tom van Stiphout" wrote: On Mon, 4 Jan 2010 17:38:01 -0800, Pamela wrote: I think the problem may be with the first line: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then Currently this line means: if there are any remarks and cbFOLConsistent = 2 then... Is that what you meant? Set a breakpoint on the first line, re-run the code, and step through, carefully inspecting the various values (either by hovering over the variable name, or by using other debugging windows, or by entering something like: ?Me.Remarks or ?Len(remarks & vbNullString) in the immediate window. I bet you some values are not what you expected them to be. -Tom. Microsoft Access MVP Hi Jeff, I think my code for the MsgBox isn't the problem but rather the If statement. I don't get an error, but no matter how I meet the criteria, I don't get the intended message box to open which makes me think that somehow my double criteria (If w/ AND) is the problem. Any ideas?? Pamela "Jeff Boyce" wrote: Pamela If MsgBox("blah, blah, blah", vbYesNo,"Title of msgbox") = vbYes Then Try checking Access HELP on the MsgBox function... for the complete syntax. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Pamela" wrote in message ... I am getting a syntax error on this code. The code is intended to check that the user entered data into the Remarks field if they also selected the text that goes with the ID # 2 in cbFOLConsistent. ID (AutoNumber,pk) is the bound control in my cbo but it displays text. I want the Msgbox to display Yes/No buttons and on Yes set focus to Remarks so that the user is forced to make their explanation. In the No case, I want the focus set to Me.Parent!cbFOLConsistent so that the user can change their selection. I actually had a lot more text in my msgbox but since I was having trouble, trimmed it to narrow down my mistake so I understand that the box doesn't make sense as it is. Here's my code: If Len(Me.Remarks & vbNullString) And Me.Parent!cbFOLConsistent = "2" Then If MsgBox("If the Facts of Loss are not consistent with the damage,") = vbYes Then Me.Remarks.SetFocus Else Me.Parent!cbFOLConsistent.Undo Response = acDataErrContinue End If End If Thanks for your help! Pamela . . |
Thread Tools | |
Display Modes | |
|
|