PC Review


Reply
Thread Tools Rate Thread

Before Update not checking combobox!

 
 
=?Utf-8?B?Sk9N?=
Guest
Posts: n/a
 
      1st Mar 2006
I have 2 comboboxes on my form, (AcctDecision, AcctCode)
AcctDecision has the following values in it... (Accept, Deny, Pending)
AcctName has the following names ( XYZ, ABC, DEF)

So what I am getting into is that if I select Pending in the AcctCode
Combobox, I need to select something in the AcctName. My code is making me
be able to save the record with the ACCTName blank when the Acct Code is
Pending.

Dim StrControl as string

strControl = ""
If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
strControl = strControl & "Select an Account Name" & vbCrLf
Cancel = True
End If

if strControl <>"" then
msgbox " Enter missing informatio": & vbcrlf & strcontrol,
vbinformation, "Incomplete Information"
End if

 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      1st Mar 2006
Move the code into the BeforeUpdate event of the *form*, not that of the
control.

You have no idea which box the user will fill in first, or which order they
will change them. Form_BeforeUpdate will fire just before the record is
saved, so cancelling this event will prevent the save.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"JOM" <(E-Mail Removed)> wrote in message
news:8D87155D-3530-45B6-A34C-(E-Mail Removed)...
>I have 2 comboboxes on my form, (AcctDecision, AcctCode)
> AcctDecision has the following values in it... (Accept, Deny, Pending)
> AcctName has the following names ( XYZ, ABC, DEF)
>
> So what I am getting into is that if I select Pending in the AcctCode
> Combobox, I need to select something in the AcctName. My code is making
> me
> be able to save the record with the ACCTName blank when the Acct Code is
> Pending.
>
> Dim StrControl as string
>
> strControl = ""
> If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
> strControl = strControl & "Select an Account Name" & vbCrLf
> Cancel = True
> End If
>
> if strControl <>"" then
> msgbox " Enter missing informatio": & vbcrlf & strcontrol,
> vbinformation, "Incomplete Information"
> End if



 
Reply With Quote
 
=?Utf-8?B?T2Zlcg==?=
Guest
Posts: n/a
 
      1st Mar 2006
Two things to check first
1. If you are entering the code.
Put a code break on the first line of the code (Press F9 while the cursor on
this line), then step the code using the F8 key

2. Check the value of Me!AcctCode if it's Null or empty.
You can use

If Me!AcctDecision.Column(1) = "Pending" And len(Me!AcctCode & "") = 0 Then

--
\\// Live Long and Prosper \\//
BS"D


"JOM" wrote:

> I have 2 comboboxes on my form, (AcctDecision, AcctCode)
> AcctDecision has the following values in it... (Accept, Deny, Pending)
> AcctName has the following names ( XYZ, ABC, DEF)
>
> So what I am getting into is that if I select Pending in the AcctCode
> Combobox, I need to select something in the AcctName. My code is making me
> be able to save the record with the ACCTName blank when the Acct Code is
> Pending.
>
> Dim StrControl as string
>
> strControl = ""
> If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
> strControl = strControl & "Select an Account Name" & vbCrLf
> Cancel = True
> End If
>
> if strControl <>"" then
> msgbox " Enter missing informatio": & vbcrlf & strcontrol,
> vbinformation, "Incomplete Information"
> End if
>

 
Reply With Quote
 
=?Utf-8?B?Sk9N?=
Guest
Posts: n/a
 
      1st Mar 2006
Allen the code is in the beforeupdate event of the form.....

"Allen Browne" wrote:

> Move the code into the BeforeUpdate event of the *form*, not that of the
> control.
>
> You have no idea which box the user will fill in first, or which order they
> will change them. Form_BeforeUpdate will fire just before the record is
> saved, so cancelling this event will prevent the save.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "JOM" <(E-Mail Removed)> wrote in message
> news:8D87155D-3530-45B6-A34C-(E-Mail Removed)...
> >I have 2 comboboxes on my form, (AcctDecision, AcctCode)
> > AcctDecision has the following values in it... (Accept, Deny, Pending)
> > AcctName has the following names ( XYZ, ABC, DEF)
> >
> > So what I am getting into is that if I select Pending in the AcctCode
> > Combobox, I need to select something in the AcctName. My code is making
> > me
> > be able to save the record with the ACCTName blank when the Acct Code is
> > Pending.
> >
> > Dim StrControl as string
> >
> > strControl = ""
> > If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
> > strControl = strControl & "Select an Account Name" & vbCrLf
> > Cancel = True
> > End If
> >
> > if strControl <>"" then
> > msgbox " Enter missing informatio": & vbcrlf & strcontrol,
> > vbinformation, "Incomplete Information"
> > End if

>
>
>

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      1st Mar 2006
If you are using Form_BeforeUpdate, and the event is not cancelling, then
the condition is not being met.

For debugging purposes, break the line into 2:

If Me!AcctDecision.Column(1) = "Pending" Then
Debug.Print "Pending"
If IsNull(Me!AcctCode) Then
Debug.Print "AcctCode is null. Cancelling."
Cancel = True
strControl = strControl & "Select an Account Name" & vbCrLf
End If
End If

Add an inappropriate record, and see which part of the condition is not
being met. For example, the second column of your combo may not contain
"Pending" (remember the Column() property is zero-based), or the AcctCode
might contain a zero-length string instead of a null (which you can avoid by
setting its Allow Zero Length property to No in table design.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"JOM" <(E-Mail Removed)> wrote in message
news:37E369DA-C83F-446B-AE1A-(E-Mail Removed)...
> Allen the code is in the beforeupdate event of the form.....
>
> "Allen Browne" wrote:
>
>> Move the code into the BeforeUpdate event of the *form*, not that of the
>> control.
>>
>> You have no idea which box the user will fill in first, or which order
>> they
>> will change them. Form_BeforeUpdate will fire just before the record is
>> saved, so cancelling this event will prevent the save.
>>
>> "JOM" <(E-Mail Removed)> wrote in message
>> news:8D87155D-3530-45B6-A34C-(E-Mail Removed)...
>> >I have 2 comboboxes on my form, (AcctDecision, AcctCode)
>> > AcctDecision has the following values in it... (Accept, Deny, Pending)
>> > AcctName has the following names ( XYZ, ABC, DEF)
>> >
>> > So what I am getting into is that if I select Pending in the AcctCode
>> > Combobox, I need to select something in the AcctName. My code is
>> > making
>> > me
>> > be able to save the record with the ACCTName blank when the Acct Code
>> > is
>> > Pending.
>> >
>> > Dim StrControl as string
>> >
>> > strControl = ""
>> > If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
>> > strControl = strControl & "Select an Account Name" & vbCrLf
>> > Cancel = True
>> > End If
>> >
>> > if strControl <>"" then
>> > msgbox " Enter missing informatio": & vbcrlf & strcontrol,
>> > vbinformation, "Incomplete Information"
>> > End if



 
Reply With Quote
 
=?Utf-8?B?Sk9N?=
Guest
Posts: n/a
 
      1st Mar 2006
I tried as you said but the part that is not being met is the If
IsNull(Me!AcctCode) Then
Everything else seems to be working ok, using the code you wrote. that
cmbobox is supposed to have something only when Pending is selected.
Any other reason this could be misbehaving....

"Allen Browne" wrote:

> If you are using Form_BeforeUpdate, and the event is not cancelling, then
> the condition is not being met.
>
> For debugging purposes, break the line into 2:
>
> If Me!AcctDecision.Column(1) = "Pending" Then
> Debug.Print "Pending"
> If IsNull(Me!AcctCode) Then
> Debug.Print "AcctCode is null. Cancelling."
> Cancel = True
> strControl = strControl & "Select an Account Name" & vbCrLf
> End If
> End If
>
> Add an inappropriate record, and see which part of the condition is not
> being met. For example, the second column of your combo may not contain
> "Pending" (remember the Column() property is zero-based), or the AcctCode
> might contain a zero-length string instead of a null (which you can avoid by
> setting its Allow Zero Length property to No in table design.)
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "JOM" <(E-Mail Removed)> wrote in message
> news:37E369DA-C83F-446B-AE1A-(E-Mail Removed)...
> > Allen the code is in the beforeupdate event of the form.....
> >
> > "Allen Browne" wrote:
> >
> >> Move the code into the BeforeUpdate event of the *form*, not that of the
> >> control.
> >>
> >> You have no idea which box the user will fill in first, or which order
> >> they
> >> will change them. Form_BeforeUpdate will fire just before the record is
> >> saved, so cancelling this event will prevent the save.
> >>
> >> "JOM" <(E-Mail Removed)> wrote in message
> >> news:8D87155D-3530-45B6-A34C-(E-Mail Removed)...
> >> >I have 2 comboboxes on my form, (AcctDecision, AcctCode)
> >> > AcctDecision has the following values in it... (Accept, Deny, Pending)
> >> > AcctName has the following names ( XYZ, ABC, DEF)
> >> >
> >> > So what I am getting into is that if I select Pending in the AcctCode
> >> > Combobox, I need to select something in the AcctName. My code is
> >> > making
> >> > me
> >> > be able to save the record with the ACCTName blank when the Acct Code
> >> > is
> >> > Pending.
> >> >
> >> > Dim StrControl as string
> >> >
> >> > strControl = ""
> >> > If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
> >> > strControl = strControl & "Select an Account Name" & vbCrLf
> >> > Cancel = True
> >> > End If
> >> >
> >> > if strControl <>"" then
> >> > msgbox " Enter missing informatio": & vbcrlf & strcontrol,
> >> > vbinformation, "Incomplete Information"
> >> > End if

>
>
>

 
Reply With Quote
 
=?Utf-8?B?Sk9N?=
Guest
Posts: n/a
 
      1st Mar 2006
It worked, since my 2nd control was a cmbbox, I added .column(0) and it
worked! thatnks for your input!

"Allen Browne" wrote:

> If you are using Form_BeforeUpdate, and the event is not cancelling, then
> the condition is not being met.
>
> For debugging purposes, break the line into 2:
>
> If Me!AcctDecision.Column(1) = "Pending" Then
> Debug.Print "Pending"
> If IsNull(Me!AcctCode) Then
> Debug.Print "AcctCode is null. Cancelling."
> Cancel = True
> strControl = strControl & "Select an Account Name" & vbCrLf
> End If
> End If
>
> Add an inappropriate record, and see which part of the condition is not
> being met. For example, the second column of your combo may not contain
> "Pending" (remember the Column() property is zero-based), or the AcctCode
> might contain a zero-length string instead of a null (which you can avoid by
> setting its Allow Zero Length property to No in table design.)
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "JOM" <(E-Mail Removed)> wrote in message
> news:37E369DA-C83F-446B-AE1A-(E-Mail Removed)...
> > Allen the code is in the beforeupdate event of the form.....
> >
> > "Allen Browne" wrote:
> >
> >> Move the code into the BeforeUpdate event of the *form*, not that of the
> >> control.
> >>
> >> You have no idea which box the user will fill in first, or which order
> >> they
> >> will change them. Form_BeforeUpdate will fire just before the record is
> >> saved, so cancelling this event will prevent the save.
> >>
> >> "JOM" <(E-Mail Removed)> wrote in message
> >> news:8D87155D-3530-45B6-A34C-(E-Mail Removed)...
> >> >I have 2 comboboxes on my form, (AcctDecision, AcctCode)
> >> > AcctDecision has the following values in it... (Accept, Deny, Pending)
> >> > AcctName has the following names ( XYZ, ABC, DEF)
> >> >
> >> > So what I am getting into is that if I select Pending in the AcctCode
> >> > Combobox, I need to select something in the AcctName. My code is
> >> > making
> >> > me
> >> > be able to save the record with the ACCTName blank when the Acct Code
> >> > is
> >> > Pending.
> >> >
> >> > Dim StrControl as string
> >> >
> >> > strControl = ""
> >> > If Me!AcctDecision.Column(1) = "Pending" And IsNull(Me!AcctCode) Then
> >> > strControl = strControl & "Select an Account Name" & vbCrLf
> >> > Cancel = True
> >> > End If
> >> >
> >> > if strControl <>"" then
> >> > msgbox " Enter missing informatio": & vbcrlf & strcontrol,
> >> > vbinformation, "Incomplete Information"
> >> > End if

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking table entries vs ComboBox value DubboPete Microsoft Access Form Coding 4 4th Jun 2008 11:32 AM
checking if combobox any item choose Marco Microsoft Access Form Coding 2 2nd Apr 2008 05:53 PM
ComboBox: Update a value in current record before changing the ComboBox Value disneygoof via AccessMonster.com Microsoft Access Form Coding 2 17th Mar 2008 02:43 PM
Windows update stalls when checking for latest version of update software Jeff Windows XP General 2 9th Nov 2003 01:33 AM
checking for errors in combobox's Bob C Microsoft Excel Programming 1 4th Sep 2003 09:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:59 AM.