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

Not sure if this is possible?

Status
Not open for further replies.
Jun 20, 2003
40
GB
I'll try and explain the best I can.

Table_1 as the field "Customer"
Table_2 as the field "Customer"

I would like to enter data into Tabel_1 using a Form. I would like to firstly lookup from Table_2 an entry for "Customer" but would also like to update Table_2 if the entry does no exist in Table_2 from the new entry in Table_1.

I hope that sounds right, please ask further questions.

Thanks for the help in advance.
 
Hi,
It is possible, but you will have to use VBA and some SQL statements:

1) Somewhere in the FROM code, once you have provided the information of the customer or Table_1:

Dim sSQL As String
Dim DB As Database
Dim RS As Recordset

sSQL = "SELECT * FROM Table_2 " & _
&quot;WHERE Customer = &quot; & <here you have to put the value>
Set DB = CurrentDb
Set RS = DB.OpenRecordset(sSQL)

'Refresh the recordset
If Not RS.EOF Then
RS.MoveLast
RS.MoveFirst
End If

'If the count is less than 1, the customer do not exist in Table_2
If RS.RecordCount < 1 Then
sSQL = &quot;INSERT INTO Table_2 (Customer) VALUES (&quot; & <here you have to put the value> & &quot;)&quot;
Call DB.Execute(sSQL)
End If

RS.Close
DB.Close
Set RS = Nothing
Set DB = Nothing

Of course you can use a Append Query with a parameter to replace the Insert SQL statement

Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top