Senin, 20 Agustus 2012

RE: [MS_AccessPros] Need help with Error Trapping in vba

 

Hello Jim

The Change event fires every time the text in the textbox changes, which is
usually when a key is pressed.

A barcode scanner mimics the pressing of several keys, one for each
character, followed by pressing <enter>, so I suspect your Change event
procedure is being called many times for each scan. After the 29th
character has been "pressed", then the Len()=29 condition will be true, and
the record will be saved, whether or not there are more characters to go.

Instead, you should be using the BeforeUpdate event to validate the data -
something like this:

Private Sub SID_BeforeUpdate(Cancel as integer)
If Len(SID.Text) > 29 then
lblstep.Visible = True
lblstep.Caption = "Please slide black strip side."
Cancel = true
ElseIf Len(SID.Text) < 29 then
lblstep.Visible = True
lblstep.Caption = "Insufficient data. Please scan again."
Cancel = true
End If
End Sub

Good luck :-)
Graham

> From: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of luvmymelody
> Sent: Tuesday, 21 August 2012 10:56
> To: MS_Access_Professionals@yahoogroups.com
> Subject: [MS_AccessPros] Need help with Error Trapping in vba
>
>  
> Hello all,
>
> I have a form that is taking a scan from a card from the black strip side.
I have that working great. But if the user tries to use the gold strip side,
there are different numbers that we do not want. It is bank information that
means nothing to us. We only need 29 characters of the black strip so my
code reflects that. The gold strip has more than 30 characters. But I cannot
figure out how to have some validation to give a message when the user
slides the gold side of the card.
>
> Can anyone take a look and give me some help.
>
> Thank You
>
> Jim Wagner
>
> Private Sub SID_Change()
>
> If Len(Me.SID.Text) = 29 Then
> If Me.Dirty Then Me.Dirty = False
>
> 'Private Sub SID_AfterUpdate()
> 'If Len(Me.SID.Text) > 30 Then
> 'lblstep.Visible = True
> 'lblstep.Caption = "Please slide black strip side."
> '
> End If
> 'End Sub
>
> 'Else
>
> 'If Me.Dirty Then Me.Dirty = False
>
> lblstep.Visible = True
> lblstep.Caption = "Step 2: Please step on the scale until this message
disappears..."
> 'End If
>
> SID.ForeColor = vbWhite
>
> Dim PauseTime, Start
> PauseTime = 9
> Start = Timer
> Do While Timer < Start + PauseTime
> DoEvents
> Loop
>
> DoCmd.GoToRecord acForm, "Suncard", acNewRec
> lblstep.Visible = False
>
> DoCmd.RunMacro "Macro1"
>
> DoCmd.OutputTo acOutputTable, "Archive", _
> acFormatXLS, "Barrett.xls", False
>
> End Sub


__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar