Add record to table from form

The Bey

Registered User.
Local time
Today, 11:35
Joined
Jun 21, 2011
Messages
84
I have a form which pulls data from another form and I need to get that data to be added to a seperate table.

I have a button which will run this coding, but what is the code that i need to use to do this?

I saw a similar thread to this about creating a form from a table but I cannot do that as my form is already bound to another source
 
You don't need the same data in two tables.
 
The same data won't be in two tables. I'd like to add/update data to an existing table.

I've just run up a mock table to test out a method that I found on a different forum, but this adds the data to the table regardless of whether or not it is a duplicate. The code I've used is:

Private Sub cmdAddData_Click()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblTrial", dbOpenDynaset, dbSeeChanges)
With rs
.AddNew
rs!UniqueID = Me.txtID
rs!Equipment = Me.txtEquipment
rs!Service = Me.txtService
rs!Hydrocarbon = Me.txtHC
rs!AdditionalAccess = Me.txtAccess
rs!Instrument = Me.txtInstrument
rs!ImpulseLineMaterial = Me.txtMaterial
rs!Lagged = Me.txtLag
rs!Tracing = Me.txtTraced
rs!InspectionDate = Me.txtDate
rs!Comments = Me.txtComments

If Me.txtMaterial = "Carbon Steel" Then
rs!MaterialAction = Me.txtCMatRef
Else
rs!MaterialAction = Me.txtSMatRef
End If

If Me.txtMaterial = "Carbon Steel" Then
rs!InsulationAction = Me.txtCInsRef
Else
rs!InsulationAction = Me.txtSInsRef
End If

If Me.txtMaterial = "Carbon Steel" Then
rs!MetallurgyAction = Me.txtCTransRef
Else
rs!MetallurgyAction = Me.txtSTransRef
End If

If Me.txtMaterial = "Carbon Steel" Then
rs!TracingAction = Me.txtCTraceRef
Else
rs!TracingAction = Me.txtSTraceRef
End If

.Update
End With
End Sub

I'm looking elsewhere and it seems like I need to add something that questions whether it's an ".AddNew" or an ".Edit"
 
Well I've changed the ".AddNew" to ".Edit" and now it just edits the current data, which is definitely a plus.

The problem I have now is that it will add a blank entry if the user were to go through with the form and add with no data in textboxes.

How do I go about setting it so that the form will not add an entry unless a specific criteria is satisfied?
 

Users who are viewing this thread

Back
Top Bottom