Mike
Mike

Reputation: 4405

Programming Check Box in MS Access

I am programming a simple check box in MS Access. This is how it goes:

  1. I have a combobox set up with a drop down of values the user can choose from.(e.g. b1, b2, c1, d1, d2, d3, e0, e2, etc) They are just 2 characters text string.
  2. I have a checkbox to be used when the user wants to modify the value in the drop down. Basically all it does is, when the checkbox is checked, it will change any of the values to 'ds(drop down value)" so it just adds the "ds()". (e.g. ds(b1), ds(b2), ds(c1), etc)
  3. If the user unchecks the checkbox, then the value stays as the 2 character text string.

This is my first foray into Access programming. My pseudo code is as follows:

Private Sub distchk_Click()
if distchk is checked then
   Me.ECOSITE = "ds(" & Me.ECOSITE & ")"
else:
   Me.Ecosite
End Sub

I tested:

Private Sub distchk_Click()
Me.ECOSITE = "ds(" & Me.ECOSITE & ")"
End Sub

but it keeps adding additional ds() anytime I check it, and won't remove it if I uncheck it.

Any suggestions would be great!

Mike

Upvotes: 0

Views: 1163

Answers (1)

mwolfe02
mwolfe02

Reputation: 24207

You are making unnecessary work for yourself and a more confusing interface for your users. You are collecting two discrete pieces of data: LandCoverType (a Text field) and IsDisturbed (a Yes/No field, aka boolean or bit field) so I see no reason to combine them in an input form. You are not providing the user with any additional information by wrapping the land cover types in "ds()". I would suggest two alternative approaches:

Two separate fields (preferred method)

  • create a LandCoverType field (Text); bind your combobox to this field (in the ComboBox ControlSource enter LandCoverType)
  • create an IsDisturbed field (Yes/No); bind your checkbox to this field (same way as above)
  • if you want to display the "ds()" on a report, then do that as part of the formatting of the report field (eg, =IIf([IsDisturbed], "ds(" & [LandCoverType] & ")", [LandCoverType]))

One combined field

  • create a single LandCoverType field (text)
  • change the RowSource of your combobox to include all of your LandCoverType's with and without the ds() (eg, if your RowSource is a value list: b1, b2, c1, ds(b1), ds(b2), ds(c1))

Upvotes: 3

Related Questions