Re: Problem with button on form
From: JP (jnospamperelst_at_optnospamonline.net)
Date: 02/03/05
- Next message: Sprinks: "RE: lookup combo box in subform"
- Previous message: Harrison: "Radio Button blank but Test is highlited"
- In reply to: Tom: "Problem with button on form"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 3 Feb 2005 11:46:56 -0500
The problem is that you've told Access that it cannot allow the user to
leave the Operator_Id textbox without validating. Because you're using
events tied to the Operator_ID textbox, it's going to do that validating
BEFORE it recognizes any input from the command buttons. The sequence of
event recognition is going to be:
Operator_ID Exit
Operator_ID LostFocus
CommandButton Enter
CommandButton GotFocus
CommandButton Click
Thus, if the Operator_ID LostFocus is not going to know that a command
button has been clicked -- it's only going to know that it has lost the
focus. In other words, you can't use a lost focus event on the textbox to
capture the command button input.
You need to re-structure the form so that the validation does not occur as a
result of the textbox Exit or LostFocus events. Probably the best bet is to
have a command button to validate the operator ID, and then use some VBA
code (or update a table) to make sure that a valid operator ID has been
entered before you start receiving barcode data from the factory floor.
Since you're using the Exit event to validate the operator ID, I assume that
there are other controls on the form to do things like start receiving the
data. If so, then you can tie the validation to one of those controls.
"Tom" <tmillington@aavf.co.uk> wrote in message
news:GeGdnd0fNZmeRpzfRVnytQ@eclipse.net.uk...
> Hi
>
> I have been working with Access for a number of years but grope in the
dark
> as far as VBA is concerned (ie, don't know a lot).
>
> I am developing a small application for reading barcode data for our
factory
> shop floor. The problem I am having is with one of the forms.
>
> When the form is opened, focus is set on a text box called [OPERATOR_ID].
> This is where the user scans their ID card resulting in their ID card
number
> and staff number being stored here. So far, so good.
>
> On the 'On Exit' control, I have set some code to check to see if the
> [OPERATOR_ID] and [CARD_STATUS] is valid. This also works fine.
>
> The problem I have is that I want the user to be able to click on one of
two
> other buttons on the form: one to 'reset' the form so they can start
again;
> one to 'exit' the form. These buttons are called 'New_Entry_button' and
> 'exit' respectively. Without the code control on the [OPERATOR_ID] text
box,
> these also work fine. However, with the code in place, the user cannot get
> past the [OPERATOR_ID] box: ie, unless they have entered a valid operator
> number, they cannot click on the 'New_Entry_button' or the 'exit' button
as
> they just get the error message from exiting the [OPERATOR_ID] box and
focus
> is returned there. The coding I have used on the [OPERATOR_ID] box's 'On
> Exit' control is as follows.
>
> ============
> Private Sub OPERATOR_ID_Exit(Cancel As Integer)
> If IsNull(Me!OPERATOR_ID) Then
> MsgBox "You Cannot Proceed Without Entering An Operator Number"
> Me!OPERATOR_ID.SetFocus
> DoCmd.CancelEvent
> ElseIf Me!CARD_STATUS <> "A" Or IsNull(Me!CARD_STATUS) Then
> MsgBox "Illegal Card or Card Status Inactive - Contact Administrator"
> Me!OPERATOR_ID.SetFocus
> Me!OPERATOR_ID = ""
> DoCmd.CancelEvent
> End If
> End Sub
> ============
>
> I was thinking of trying to test to see if one of the buttons has been
> clicked but this is beyond my knowledge of VBA. I guessed this could be
done
> on the 'lost focus' control on [OPERATOR_ID].
>
> Could someone help me with this please?
>
> Regards
>
> Tom
>
>
>
- Next message: Sprinks: "RE: lookup combo box in subform"
- Previous message: Harrison: "Radio Button blank but Test is highlited"
- In reply to: Tom: "Problem with button on form"
- Messages sorted by: [ date ] [ thread ]