Update indexed records/add new record

Izzygrace3

New member
Local time
Today, 15:44
Joined
Jul 27, 2011
Messages
5
I have a form that has a combo box to that autopopulates the other fields on the table. I would like for the form to update existing data for a record, if such data exist or to add a new record if no information exist. So far, the form just makes a new entry each time you open the form as opposed to updating existing data. Any help would be greatly appriciated.

Here is the code on the after update event of the combo box:

Private Sub Unit_AfterUpdate()
Me.POC = Me.Unit.Column(1)
Me.[Phone Number] = Me.Unit.Column(2)
Me.[Orders Clerk] = Me.Unit.Column(3)
Me.[Phone Number2] = Me.Unit.Column(4)
End Sub
 
You're going to need tp write some VBA to do all that, something like...

Code:
If DLookup("FieldFromTableOrQuery", "YourTableOrQuery", "[FieldFromTableOrQuery]=" & Me![FieldFromForm]) Then
Run Update Query here
Else
Me.POC = Me.Unit.Column(1)
Me.[Phone Number] = Me.Unit.Column(2)
Me.[Orders Clerk] = Me.Unit.Column(3)
Me.[Phone Number2] = Me.Unit.Column(4)
End If

If field is TEXT use...
DLookup("FieldFromTableOrQuery", "YourTable", "[FieldFromTableOrQuery]='" & Me![FieldFromForm] & "'")
 

Users who are viewing this thread

Back
Top Bottom