saving data from a form using tableA to tableB

noks

Registered User.
Local time
Today, 00:56
Joined
Mar 2, 2007
Messages
51
Hi guys

Can you please help me with the syntax to save data within a form using tblA to tblB (whicheva changes i make on the form, i want saved on both tables)

i've tried this whenever i click the done command but it's not workin :rolleyes:

CODE:
DoCmd.RunCommand acCmdSaveRecord

Dim strAll As String
Dim insertHistory As String

strAll = "SELECT almost.*"
strAll = strAll & "FROM almost, History"
strAll = strAll & "WHERE [forms]![molo]![Customercode] = almost.customercode "


insertHistory = "INSERT INTO history ( SELECT strAll.* FROM strAll )"
End Sub
 
Hello noks!

1) You don't need the same data in two tables.
2) If you want it, try to do it with APPEND QUERY (in tbl B).
 
Actually i do need it to keep the history. the primary for tbl2 is customercode_date wich is the combination of customercode & date

As for appending this is what am trying to do with dis code

insertHistory = "INSERT INTO history ( SELECT strAll.* FROM strAll )"
 
Hello noks!

Look at "DemoTblATblBA2000.mdb".
Look at tables, Query1Append.
Open FormA and try.
 

Attachments

i've tried yo way which help coz it turned out that i had to fix the table first. but. here's ma code

insertHistory = "INSERT INTO History (SELECT almost.customercode"
insertHistory = insertHistory & " FROM almost, History)"
insertHistory = insertHistory & " WHERE me.Customercode = almost.customercode)"

MsgBox (insertHistory)
DoCmd.RunSQL insertHistory

am running into a error coz of the last line

error msg "Syntax error in INSERT INTO statement. (Error 3134) "

I haven't used any reserved words or anythin of a kind. Pls kindly help
 
Last edited:
Why are you building string SQl instead of using a stored querydef?

I don't understand why you need two tables, anyway. If you need the history, why keep table A? You just need the most recent record in table B.
 
what about:

insertHistory = "INSERT INTO History (SELECT almost.customercode " & _
"FROM almost, History " & _
"WHERE almost.customercode = '" & me.Customercode & "');"

isn't any relation between almost and history? for each recod in almost, will display all records from History... at least a Group by.
 

Users who are viewing this thread

Back
Top Bottom