Selecting one option only

  • Thread starter Thread starter Michelle F
  • Start date Start date
M

Michelle F

I would like my users to enter either a project number or a record number
(not both) either with a default setting like...

If ProjectID=NotEmpty
then RecordNumber.Visible=False
elseif RecordNumber.Visible=True
end

or with a option group with check boxes that make visible the entry method
the user selects.

Help with either option code would be most appreciated!

Michelle
 
Michelle,
Show both both textboxes.
On the after update event for txtProjectID
If Not IsNull(Me.txtProjectID) Then
Me.txtRecordNumber.Locked = True
Else
Me.txtRecordNumber.Locked = False
End If

Similar thing on the after update for txtRecordNumber

Then you could do something like this on the before update event for the
form.
If IsNull(me.txtProjectID) and IsNull(me.txtRecordNumber) then
Cancel = True
Msgbox "You must enter a ProjectID or a record number"
End If

Jeanette Cunningham
 
So you have a table with 2 fields named
ProjectNumber
RecordNumber
In the form bound to this table, the user must enter one or the other, not
both. You can do that with a validation rule on the table.

1. Open the table in design view.

2. Open the Properties box (View menu.)

3. In the Validation Rule in the Properties box, enter:
([ProjectNumber] Is Not Null) XOR ([RecordNumber Is Not Null)

4. (Optional) Beside the Validation Text, enter:
Enber a project number or a record number (not both.)

Be sure to use the Validation Rule in the Properties box, not the one in the
lower pane of table design (which applies to one field only.)

For more information on validation rules, see:
http://allenbrowne.com/ValidationRule.html
 
Option 1: use each controls before update event to check the other control
for null (or in this case not null)

Private Sub ProjectID Before_Update(Cancel as Integer)

If Not IsNull(Me.RecordID) Then

MsgBox "You already entered a Record number", vbOKOnly, "Invalid Entry"
Cancel = True
Me.RecordID.SetFocus

EndIf

End Sub

Private Sub RecordID Before_Update(Cancel as Integer)

If Not IsNull(Me.ProjectID) Then

MsgBox "You already entered a Project number", vbOKOnly, "Invalid Entry"
Cancel = True
Me.ProjectID.SetFocus

EndIf

End Sub

Option 2: Enable/Disable the controls based on the selection in an option
group, using the current event of your form

Private Sub Form_Current

Select Case Me.OptionGroup

Case 1
Me.ProjectID.Enabled = True
Me.RecordID.Enabled = False

Case 2
Me.RecordID.Enabled = True
Me.ProjectID.Enabled = False

End Select

End Sub

You could use check boxes also, but if you do that you'll have to add some
additional code to make sure that both boxes can't be checked (true) at the
same time. Not a big deal, but an option group is probably a little easier.

HTH
 
I like the option of using an option group rather than just a validation
rule, the dynamic form will impress my boss. I input the code as Beetle
wrote and it appears to be working but it doesn't really actively update the
form.

For instance, if I select the option that I want to input using the
ProjectID, nothing happens, but if I switch to design view then right back to
data view, the recordID field is disabled. Then if I select the RecordID
input option, nothing changes, the RecordID field is still disabled. But, if
I once again switch to the design view and right back to the data view, the
RecordID input field is enabled and the ProjectID field is disabled. It
seems like it only works when I switch back and forth between the design and
data views. How can I make this actively update within the form without
exiting the form and then coming back to it?
 
Back
Top