How do I prevent the wrong entry in a field with multiple conditio

G

Guest

I have a form with a sequence of the same blank fields, which the user fills
from another form control. The idea is that they select what they consider is
the correct address, and the control sends the data to the next available
empty field on the Target Form.

All works well; except for when the user selects the incorrect entry, the
action still takes place, and the incorect entry is placed in the empty
field, and due to the nature of the action, the sequence moves to the next
available empty field.

I need a way of dealing with the incorrect entry. What I want to happen is
nothing. Just leave the available field empty, and… available for the next
attempt at getting it right. I suppose what I am asking is the possibility of
having an ‘If’ multiple condition, but I can’t seem to code for that scenario.

Which would be somehting like:

If the target field is blank
AND the target field is the correct match

Then fill it it.
If not, just leave it available for antother try.



This is the code on my ‘Field Selector Control’, which works so far as
described above.

Private Sub Waypoint_Selector_Click()

If IsNull(Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Me.Waypoint_Selector

Else
Parent.frm_Run_Test.SetFocus
Parent.frm_Run_Test.Form.Waypoint_Combo.SetFocus
RunCommand acCmdRecordsGoToNext

If IsNull(Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Me.Waypoint_Selector

Else
MsgBox "All fields are filled"
End If

End If
End Sub


This is my Code for the ‘Target Control’ based on a After Update property:

Private Sub Waypoint_Combo_AfterUpdate()
With CodeContextObject
If (Waypoint_Combo = Run_waypoint) Then
AnswerBox_Waypoint = -1
End If

If (Waypoint_Combo <> Run_waypoint) Then
AnswerBox_Waypoint = 0
Waypoint_Combo = Null
End If

End With
DoCmd.GoToRecord , , acNext

End Sub

I tried the line ‘Waypoint_Combo = Null’ in the above code, but it didn’t work

Can someone help me understand where I’m going wrong?
 
G

Guest

Steve,

Since posting , my code has moved on a little; but essential the checking
comes from a combinatio of the this first line routine.

'If the Target field is empty then place the Selection into the Target
Field

If IsNull(Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Me.Waypoint_Selector

and this line further down...

'This checks if the selection is wrong, if so, then reset (blank) the
waypoint target

If (Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] <>
Forms.Runs.[frm_Run_Test].Form.[Run_waypoint]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Null


I know it's not elegant, but with my limited coding skills and lack of
experience with nesting and calling routines, it's the best i can do.

Here is my complete code so far, created with a lot of trial and error of
moving End If's around, and some help from Marshall Barton and SusanV on this
forum, but it does work... Though, If you can think of a cleaner, more
elegant way of doing it, i would love to hear your suggestion. If you are
unclear of what i am trying to acheive, just let me know and I will attempot
to explain.

Meanwhile, here's the complete code.

Private Sub Waypoint_Selector_Click()
If IsNull(Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Me.Waypoint_Selector

Parent.frm_Run_Test.SetFocus
Parent.frm_Run_Test.Form.Waypoint_Combo.SetFocus
DoCmd.GoToControl "Waypoint_Combo"
'This gets the Focus on the Run Test Form/Waypoint Control

If (Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] =
Forms.Runs.[frm_Run_Test].Form.[Run_waypoint]) Then
Me.Waypoint_Selector = Null
'This deletes the correct entry from the Waypoint Selections form

Parent.frm_Run_Test.SetFocus
Parent.frm_Run_Test.Form.Direction_Combo.SetFocus
RunCommand acCmdRecordsGoToNext
'This goes to next Blank Direction Field record if correct

End If

If (Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] <>
Forms.Runs.[frm_Run_Test].Form.[Run_waypoint]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Null
'This is if the selection is wrong, then reset (blank) the waypoint target


End If

Else
Parent.frm_Run_Test.SetFocus
Parent.frm_Run_Test.Form.Waypoint_Combo.SetFocus
RunCommand acCmdRecordsGoToNext

If IsNull(Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Me.Waypoint_Selector

If (Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] <>
Forms.Runs.[frm_Run_Test].Form.[Run_waypoint]) Then
Forms.Runs.[frm_Run_Test].Form.[Waypoint_Combo] = Null

End If

Else
' MsgBox "All fields are filled"
End If
'End If
End If
End Sub
 

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