Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to direct text fields on a form to a unbound table? 2

Status
Not open for further replies.

tatika

MIS
Oct 6, 2003
35
US
I created a form completely independent to my table. Now I would like to insert information to the table from a form that is not bound to the table.
Is there a way to force the field in the form to save onto the table?
 
If you open a recordset from the table, you can then set each field in the recordset equal to the corresponding field in the form and then do an update.

Something like:

Private Sub cmdSave_Click()
With frm
rs!field1 = .Field1
rs!field2 = .Field2
rs.Update
End With

You would then reconnect to the table and do an update batch.

The Jan 2002 issue of Inside Access has a marvelous article about using disconnected recordsets.
 
Here is the code that I always use when I have an unbound form and am adding records to a table from the fields on the form.


Dim cnCurrent As ADODB.Connection
Dim rsTable As ADODB.Recordset

Set cnCurrent = CurrentProject.Connection
Set rsTable = New ADODB.Recordset

rsTable.Open "TableName", cnCurrent, , adLockOptimistic, adCmdTable

With rsTable
.AddNew
![TableField1] = FormField1.Value
![TableField2] = FormField2.Value
![TableField3] = FormField3.Value
.Update
End With

rsTable.Close
cnCurrent.Close
Set rsTable = Nothing
Set cnCurrent = Nothing

 
thank you so much for the help. mkow's reply woked very well:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top