value with check box

G

Guest

I have set up a form with 10 fields set up as combo boxes. I pull values for
those boxes from source table (10 columns, one for each field in the form). I
would like to be able to check one check box on the box so that default
values will appear in all 10 combo boxes. I guess it should be something like
this
if check box is 1 (checked) then field 1 = this value
if check box is 1 (checked) then field 2 = this1 value
I do not know how to write the correct expression. ALso, I do not want to
lose the ability to pull different values from source table, in case I do not
want default value.
I hope it is clear explanation.
Thanks
 
G

Guest

Alexasha,

It is highly unlikely that you need 10 combo boxes if they are displaying
different columns from the same record frpm the same source table.

Normally, it is necessary to only store a numerical foreign key. For
example, an Orders table would have a CustomerID field, but NOT a Customer
Name, Address, Phone, etc. When interested in displaying these fields on a
form or printing them on a report, the tables would be brought together in a
query, linked by the common field.

Another way to display these other fields is to include them as columns in a
combo box, and use its Column property, setting a textbox' ControlSource to:

=MyComboBox.Column(x), where x is the column index, beginning with zero.

If in fact, the other nine form controls are meant to display other columns
from the row specified by the combo box, it would only be necessary to set
the combo box' value to a default--the others would simply display the
corresponding column values once it is set:

Dim intDefaultValue As Integer
intDefaultValue = YourValue
If Me!YourCheckbox = True Then
Me!YourComboBox = intDefaultValue
End If

Replace YourValue with the default value, and YourCheckBox and YourComboBox
with the names of your checkbox and combo box controls, respectively.

Hope that helps.
Sprinks
 
G

Guest

I guess I need to be more specific. I have medical record set up with review
of systems. I have system 1, system 2, etc. In my source table each systems
represented by separate column. The first row in source table contains normal
values for each system. Other rows contain abnormal values. So for one system
I might use normal value (row 1), for another abnormal value (row 2), and for
third value from 3d or 4th row in source table. In my report, I set up each
system on new line with label for that system. If there is no data entered in
the form field, which happens regularly, then both report field and label for
that field is blank. I do not see how I can change that, and it seems to work
fine.
Now, the expression
Dim intDefaultValue As Integer
intDefaultValue = YourValue
If Me!YourCheckbox = True Then
Me!YourComboBox = intDefaultValue
End If
seems that is might work. Should I place is in after update section? Another
question, my default value is a text, can I change first line to As Text?
Thanks for the help
 
G

Guest

Also, after looking at it is seems that I can not set up separate default
value to each field. What I think I need is something like this (to place is
in contol source)
If check box=True, then field <Field 1> value = "my text"
Can we do that?
 
G

Guest

Hi, Alexasha.

OK. It seems you do in fact need 10 combo boxes, one each corresponding to
each "system". Yes, if the value is text, use string variables instead,
however, note that if you are using a combo box, they are normally set up to
*display* text but *store* a numerical value in the underlying field. Check
the combo box' BoundColumn property--this is the column that is stored.
Since you have ten similar values, it's convenient to use an array.

Dim strDefaultValue(10) As String

If Me!YourCheckbox = True Then

strDefaultValue(0) = YourValue0
strDefaultValue(1) = YourValue1
strDefaultValue(2) = YourValue2
strDefaultValue(3) = YourValue2
strDefaultValue(4) = YourValue2
strDefaultValue(5) = YourValue2
strDefaultValue(6) = YourValue2
strDefaultValue(7) = YourValue2
strDefaultValue(8) = YourValue2
strDefaultValue(9) = YourValue2

Me!YourFirstComboBox = strDefaultValue(0)
Me!YourSecondComboBox = strDefaultValue(1)
....etc....

End If

If some are text and others numeric, use a variant array:

Dim varDefaultValue(10) As Variant

You may skip the array altogether, and just directly assign the values to
your fields--it is just standard programming practice to define constants at
the top of the code to make it easier to change later.

Yes; place the code in the checkbox' AfterUpdate event procedure. The
checkbox is presumably not bound to any field, so you'll want to uncheck it
when you go to a new record. In the form's OnCurrent event procedure:

Me!MyCheckbox = False

Hope that helps.
Sprinks
 
G

Guest

I am getting Run time error 438
Object doesn't support this property or method
Debuging highlights

Me!ROS_check = False
Can I do instead of this string the default value for checkbox to no
I tried other string for only two fields and getting the same error
Private Sub Check74_AfterUpdate()
Dim strDefaultValue(10) As String
If Me!ROS_check = True Then
strDefaultValue(0) = "NAD"
strDefaultValue(1) = "No problems"
Me!General = strDefaultValue(0)
Me!Nose = strDefaultValue(1)
End If
End Sub
Should I remove quotes (NAD, no problems)? ANy other mistakes that I have
done?
 
G

Guest

I have removed
Me!MyCheckbox = False
and set default value for check box to no. Errors disappeared, but checking
box does not produce any effects in two specified fields.
 
G

Guest

Hi, Alexasha.

There's nothing wrong with the *syntax* of the code; I tested it
successfully, so the problem must be in one of the references. I suspect
it's the checkbox. First try inserting a Msgbox statement directly after the
If test:

If Me!ROS_check = True Then
MsgBox "Got here. Me!ROS_check = True"

If the Msgbox statement does not display, then it must be that ROS_check is
not the name of your checkbox. See the Name property on the Other tab. If
this is the problem, then it was causing the error in the OnCurrent event
also, so you can insert that again.

You can't take the approach of assigning a value in the ControlSource
property, because then the value would not be bound to a table field.

Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top