Stopping update to form if value is already present

Banaticus

Registered User.
Local time
Yesterday, 20:31
Joined
Jan 23, 2006
Messages
153
I have a form based off my main table -- each record has its own number. If a person attempts to add a new record that has the same number as another record, normally Access just pops up the message noting that and stops the update. I'd like it to check such as soon as the person is done typing in the number (in the BeforeUpdate of the control), then take the person to that record.
Code:
Private Sub NumberBox()
'*********************************
'Code sample courtesy of srfreeman
'*********************************
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.Social_Security__.Value
stLinkCriteria = "[Soc Sec #]='" & SID & "'"
MsgBox (stLinkCriteria)

    'Check StudentDetails table for duplicate StudentNumber
    If DCount("[Soc Sec #]", "App Info", stLinkCriteria) > 0 Then
        'Undo duplicate entry
        Me.Undo
        'Message box warning of duplication
        MsgBox "Warning Social Security Number " _
        & SID & " has already been entered." _
        & vbCr & vbCr & "You will now been taken to the record.", vbInformation _
        , "Duplicate Information"

'Note how I've added this part here in an effort to stop the error:
        Dim ctlC As Control
        ' For each control.
        For Each ctlC In Me.Controls
            If ctlC.ControlType = acTextBox Then
                ' Restore Old Value.
MsgBox (Nz(ctlC))
                ctlC.Value = ctlC.OldValue
            End If
        Next ctlC
'This part here ^

        'Go to record of original Student Number
        rsc.FindFirst stLinkCriteria
        Me.Bookmark = rsc.Bookmark
    End If

Set rsc = Nothing
End Sub

But, it's giving me an error, saying that I'm trying to SetFocus or something before the value can be saved. The debugger is stopping at the SetFocus in the first line of this
Code:
Private Sub Text_BeltPrice_AfterUpdate()
'MsgBox ("Text_BeltPrice_AfterUpdate begins")
    Me.Text_BeltPrice.SetFocus
'MsgBox (Len([Text_BeltPrice].Text))
    If Len([Text_BeltPrice].Text) Then
        Me.RedDotImage.Visible = True
        Me.BeltPdCheck.Enabled = True
        Me.BeltReimCheck.Enabled = True
    Else
        Me.RedDotImage.Visible = False
        Me.BeltPdCheck.Enabled = False
        Me.BeltReimCheck.Enabled = False
    End If
'MsgBox ("Text_BeltPrice_AfterUpdate ends")
End Sub
That is, it stops there without that "revert every textbox to its previous value" that I run. With that "revert every..." code, the debugger hangs on:
ctlC.Value = ctlC.OldValue

Any suggestions on how I can explicitly save the value in the field before moving to the new record or something like that?
 

Users who are viewing this thread

Back
Top Bottom