Jump & Block a entry on a field

roberttran52002

Registered User.
Local time
Today, 20:49
Joined
Aug 12, 2007
Messages
27
Hi listers,

I'm very new to Access but assigned to create an entry form with some logics on entry. Would much appreciate if any one could do me a favor to tell me how to:

1/ Jump to a certain field if some other field(s) meet a criteria ie. if age>=45 & sex=2 (female) ==> Jump to Q3

2/ Block a certain field from entry if some other field(s) meet a criteria ie. if age>=45 & sex=2 (female) ==> Q2 cannot be answered (even using mouse to go back).

Thank you so much and hearing from you,

Hop
 
You can use an after update event and an if....then.....else statement like

Private Sub Combo28_AfterUpdate()
If Me.Combo28 = "male" Then
Me.Q1.SetFocus
Else
Me.Q2.SetFocus
End If
End Sub

Your could also use select case statement if you need to evaluate more than one value.

for your next question you could lock or disable the field you want with the same type of if statement me.q1.locked = true or me.q1.enabled = false:cool:
 
Hi Wiremonkey22,

Thank you so much for you advice!

The first part of jump works perfect but the second part of locking the field under a certain condition still cannot be used. Could you help tell me the way out

Private Sub v2_AfterUpdate()
If Me.v2 = 1 Then
Me.v3.SetFocus
Else
Me.v4.SetFocus
End If
End Sub

-------------

Private Sub v3_afterUpdate(Cancel As Integer)
If Me.v2 > 1 Then
Me.v3.Locked = True
End If
End Sub

Much appreciate your advice!

Hop
 
Why if v2 = 1 then your setting focus on v3 then evaluating v2 again

It looks like your evaluating v2 on both why not combine them

This is just randomness change your fields around for your need

Private Sub q2_AfterUpdate()
Select Case Me.q2
Case 1
Me.v3.SetFocus
Me.v4.Locked = True
me.v3.Locked = false
Case Is > 1
Me.v4.SetFocus
Me.v3.Locked = True
me.v4.Locked = false
'you can add more cases here'
End Select
End Sub

You can do this with if...statements but i prefer Select case myself
 
Sorry i was using q's and forgot to change a couple just use v or whatever your using
 
Sorry I had problem of log-in.

It's very kind of you! the codes works perfectly.

May I have another question:

How can i write a code that can check the missing/ redundant for:

Option group (1/ everybody must answer; 2/ all v2=2 must answer else must skip)

==> this check should be poped up before moving to the next record. Since if there is any missing in the entry, I cannot call back to patch data.

I'm trying to stop key puncher from moving to a new field/ record if the is some logic problems/ missing/ redundant. Not just pop up the warning.

Sorry to trouble you too much! Thank you so much for helping me out!

Hop
 
Last edited:
you could have a submit button click or you could do this on lost focus event something like

if isnull(me.yourfield) then
msgbox "please enter a valid whatever",vbokonly,"title here"
me.yourfield.setfocus
end if

the lost focus will check if there is anything in the field when the person tabs or clicks off of it then you can set the focus back on it so they cannot leave without filling it in dont know if you use a submit button or something like it but you can check each field before it is added to your table just as easy either way works though
may have to adjust some syntax good luck
 
Last edited:
Thank you very much for your patience. Now I've got to now the rule of on lost focus.

For the group option, it does not support the on lost focus. I tried this it it did not work:

Private Sub v4_beforeUpdate(Cancel As Integer)
If IsNull(Me.v4) Then
MsgBox "please select 1 option", vbOKOnly, "in v4"
Me.v4.SetFocus
End If
End Sub

Please enlighten me. Thank you ever so much.

TH
 
Need some info is v4 an option group or a field
options are either true or false so you wouldn't use isnull
if me.v4 = false then
.....
and you should use the after update if you want them to enter some thing or select something first before running the code

sorry if im way off hard for me to advise without seeing;)
 
I'm really grateful to your help! Sorry for not giving you enough info!

I use the group option for Single answer question [v4] (how satisfied are you with the service on the scale of 5: 5=very satisfied; 4=satisfied; 3=neutral; 2=dissatified & 1=very dissatisfied).

Before that there is a question about incidence of using the service v3: 1=yes; 2=No.

The routing is v3=1 ==> v4 must select 1 answer; v3=2 ===> v4 must not answer.

Your code work perfectly in for combo box or Y/N click. Please advise for Option group check.

Thanks once again!

TH
 
Private Sub Frame19_AfterUpdate()
If Me.Frame19 = 1 Then 'frame 19 is your option group 1 would be yes'
Me.Frame4.SetFocus 'frame 4 is the how satisfied are you option'
Me.Frame4.Locked = False 'need to unlock it incase they select no first'

Else

Me.somethingelse.SetFocus 'Set focus on something else'
Me.Frame4.Locked = True 'lock frame 4'
End If
End Sub

select case works well for multiple selections maybe try something like this

select case me.frame19

case 1
'this is the code you want ran if the user selects option 1'

case 2

case 3

case else
'if nothing is selected then you could tell them to select some thing here'
end select
 

Users who are viewing this thread

Back
Top Bottom