Hmmm...It sounds like they look the same but are not. I know this may be
overkill, but try this, just to be sure:
If Binder = Binder.DefaultValue then
MsgBox "They are the same."
Else
MsgBox "They are different"
End If
Let me know what result you get when the default is changed and when it is
not.
:
Brian,
when I use something other than the default value, select a different value
from the list, the message says Binder default: "Binder".Binder: [Selected
value]
If the Binder default is the value then Selected value becomes the binder
default value.
both turn up false
as for the . dirty comand VB is not recognizing it.
it says that Method or data member not found
Thanks,
James
:
Is the MsgBox returning the same DefaultValue and value? Do these two look
the same in the MsgBox results when the value has not been changed from the
default?
Another option to try is this:
If A.Dirty Then Run CodeA
The Dirty will cause the If to resolve to True if A has been changed from
its default value without making you code the comparison.
:
Brian,
Ok I put in the message box codes and got the answer false. the limit to
option is off, and I am putting the default value in the default value field.
Any Ideas,
James
:
Two questions to ask yourself:
1. Are you setting the DefaultValue property of each combo box in its
properties, or programmatically when you open the form (it does not sound
like you are simply populating them with a value when you open the form,
which is different from setting the default value)? You can do it
programmatically, but it is best to do this in the combo boxes' DefaultValue
properties if it is static (does not change each time you open the form).
2. If you have LimitToList turned on for each of the combo boxes, is the
default value (e.g. "Enter name") included in the valid values for the combo
box as defined by its RowSource? This will not matter if LimitToList is
turned off.
Try placing this code before any other commands in the code that runs on
your button:
MsgBox "Binder default: " & Binder.DefaultValue & ". Binder: " & Binder
MsgBox Binder.DefaultValue = Binder 'this will generate true or false
etc., etc. (Copy these for each of the other five combo boxes)
Exit Sub 'put this before any other code to interrupt it before running any
more code
This will display the default and current values of each of the controls,
one by one, in message boxes, then exit the sub so that you can compare the
default values to the current value when you click the button. If there is a
difference, then perhaps something is awry in the use of the DefaultValue
property.
One further question:
If the first two combo boxes have data entered (i.e. changed from default),
do you want to:
1. Proceed to run the code from combo box #2 immediately after #1?
2. Pause before going on to #2.
3. Simply run #1 and stop?
For any of these, you will not need to use the Else. If you want result #1,
just put a series of If...Then single-line statements like this:
If A <> A.DefaultValue Then Run CodeA
If B <> B.DefaultValue Then Run CodeB
For result #2, you can use a MsgBox, InputBox, or some other method to halt
processing so that you can review CodeA results before CodeB takes off.
If A <> A.DefaultValue Then
Run CodeA
MsgBox "CodeA done"
End If
If B <> B.DefaultValue Then
Run CodeB
MsgBox "CodeB done"
End If
To get result #3, use Exit Sub instead of the MsgBox in the #2 example
above.It will exit the sub and not progress to the next loop.
:
Brian,
Sorry I didn't respond yesterday, left work early.
Hopfuly this will help,
What I have is a search form with 6 combo boxs and a button that says begin
search. I inputed a default value such as "enter name" which it displays
just fine. but if the default value is in the combo box the code inturprits
it as if it were not the default value. In other words the code reads "enter
name" as not equal to the default value and only does the first If then
statement. however if I use the exact same code but leave the default value
property blank then the code works correctly.
Just in case here is the code i am using.
If Binder <> Binder.DefaultValue Then
DoCmd.OpenForm "tblPropellant Query", , , "BINNAM = '" &
Me!Binder.Value & "' And BINPCT between " _
& Nz(LowPCT.Value, 0) & " and " & Nz(HighPCT.Value, 0)
Exit Sub
And this model is used for all 6 if then statements, except they have elseif
instead of if.
Thanks,
James
:
I'm not quite clear on what you mean when you say the other combo boxes don't
work. If you actually have a default value coded in the DefaultValue property
of each combo box, then the following one should work to compare the current
contents of each box to its default. The third example (repeated below) runs
the code only if the value has been changed from its default. Try to give me
a little more info on what you are doing with the contents of the combo
boxes. Are you using them to generate a report or filter? I am assuming you
want to run this code when you click the button.
If ComboBox1 <> ComboBox1.DefaultValue Then
RunCode1
Exit Sub
End If
If ComboBox2 <> ComboBox2.DefaultValue Then
RunCode2
Exit Sub
End If
:
Brian,
Yeah, I meant combo boxs, couldn't remember what they were called.
I am using the code for different from default value
This works really well, except for some reason if my first combo box has a
default value none of the other combo boxs will work when I click search. I
tried changing which box has a default value and it followed suit, every
search after the one with value would bring up a blank form, my code uses
docmd.openform, and every one before it worked fine.
I would like to have values in all of the boxs, is there anything we can do?
Thanks for your help,
James
:
It sounds like your "drop-down" menus are actually combo boxes. Here is one
approach.
If Not IsNull (ComboBox1) Then
RunCode1
Exit Sub
End If
If Not IsNull (ComboBox2) Then
RunCode2
Exit Sub
End If
The above example assumes that the box would be null before the user touches
it. If you want to see if it has been changed, use this instead;
If ComboBox1.Dirty Then 'Dirty means the value has been changed
RunCode1
Exit Sub
End If
If ComboBox2.Dirty Then
RunCode2
Exit Sub
End If
If you just want to see if it is different from its default, try this:
If ComboBox1 <> ComboBox1.DefaultValue Then
RunCode1
Exit Sub
End If
If ComboBox2 <> ComboBox2.DefaultValue Then
RunCode2
Exit Sub
End If
:
Hi all,
I have a question regarding the drop down menus and coding. I want the code
to be able to tell if the user has entered anything into one of many drop
down menus. If the user has and has clicked on the comand button it should
run a particular section of code. I know I probibaly should use If Then
statements but I don't know how to make the program check the lists. I also
have a default value in the list boxs. I hope that doesnt screw it up.
In more code terms the program should do something like this
If "Listbox1" = user input Then
Run code
ElseIf "Listbox2 = user input then
Run code 2
ect.
Thanks,
James