How do I change the record my data entry form is entering to

93 Views Asked by At

Hi I am very new to vba and microsoft access. I have a data entry form with 3 comboboxes and a date box that save to the Shift, Operator, Date_Field and Machine fields of the Tracking table. These four fields are a unique index. I want the form to operate so that the person filling it out can be automatically navigated to the record that already exist if they fill in a Shift/Operator/Date/Machine combo that already exists. Right now I am testing this code in the afterupdate section of the MachineCbo combo box. I can find out if a record matching those criteria already exists, but I cannot figure out how to make it so the form is adding more data to that record.

Dim int_ID As Integer
With Me
'checks if duplicate record exists and stores it as int_ID variable
int_ID = Nz(DLookup("ID", "Tracking", "Shift= " & Val(.ShiftCbo) & _
" And Operator='" & .OpCbo.Column(1) & "' And Date_Field=#" & .DateBox _
& "# And Machine='" & .MachineCbo.Column(1) & "'"), 0)

End With
If int_ID <> 0 Then

    Dim rst As Recordset
    Dim strID As String

    Set rst = Me.RecordsetClone
    strID = CStr(int_ID)

    Debug.Print (strID)
    rst.FindFirst "ID='" & strID & "'"
    If rst.NoMatch Then
        GoTo Cleanup
    Else
        Me.Bookmark = rst.Bookmark
    End If

Cleanup:
    rst.Close
    Set rst = Nothing
End If

When I run this code It appears to go into the NoMatch if statement and I am essentially back to where I started.

0

There are 0 best solutions below