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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Records

Status
Not open for further replies.

sha123

Programmer
Nov 13, 2002
58
0
0
ZA
I have a form called FrmGrn that is based on a table called tblGrn!I also have a table called TblGrnTemp.
If I add a record to my form then I want it to add the record to both my tables and not just the one!

In the tblGrnTemp I only Want one record at a time for stock purposes!

Is it possible to do that?

Please help
 
It is possible ... add this to code to the on click event of the form and rename the button to "save_button"...

Here is an example of how to enter data to the temp table.
I have given you an example of adding a new record if none were found and where the temp table record is edited to the new value.

Private Sub save_button_click()
On Error GoTo Err_save_button_click

Dim db As Database
Dim add_to_temp_tbl_qry As Recordset
Dim add_to_master_tbl_qry As Recordset

Dim unique_item_number As String

Set db = CurrentDb()

unique_item_number = Me.FormName.textboxname.Value

Set add_to_temp_tbl_qry = db.OpenRecordset("temp_tbl", dbOpenDynaset)

With add_to_temp_tbl_qry
If Not (.EOF And .BOF) Then
add_to_temp_tbl_qry.Index = add_to_temp_tbl_qry!temp_id
add_to_temp_tbl_qry.Seek "=", unique_item_number
If add_to_temp_tbl_qry.NoMatch Then
Debug.Print "No matches found in temp"
'if there are no results - do you want to add the record?
'add the item here
'add_to_temp_tbl_qry.AddNew
'add_to_temp_tbl_qry!temp_id = unique_item_number
'add_to_temp_tbl_qry.Update
Else
'has a record and update it
add_to_temp_tbl_qry.Edit
add_to_temp_tbl_qry!temp_id = unique_item_number
add_to_temp_tbl_qry.Update
End If
Else
'if there are no results - do you want to add the record?
'add the item here
add_to_temp_tbl_qry.AddNew
add_to_temp_tbl_qry!temp_id = unique_item_number
add_to_temp_tbl_qry.Update
End If
End With

Exit_save_button_click:
Exit Sub

Err_save_button_click:
MsgBox Err.Description
Resume Exit_save_button_click

End Sub

Tiny

Perfection is Everything
If it worked first time we wont be here!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top