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

Insert giving an extra record

Status
Not open for further replies.

VKZIMM

Technical User
Jan 9, 2008
45
US
I have one table with 5 fields
Store, Year, Month, Acct#, Amount
Main form has
Store, Year and Month
Sub form has
Acct# and Amount
Everything displays fine. If the subform is blank, I added a button with the following code to add the records. There are suppose to be 5 records and I get 6. When I do Month 02, the first acct#1001 overwrites the month 01 and adds the 5 records.

Private Sub Command8_Click()
Dim strSQL As String

strSQL = "INSERT INTO Budget (Store, FiscaLYear, FiscalMonth, AccountNumber) " & _
"VALUES('" & Me.Store & "', '" & Me.FiscalYear & "','" & Me.FiscalMonth & "', '1001' ) ;"

CurrentDb.Execute strSQL
strSQL = "INSERT INTO Budget (Store, FiscaLYear, FiscalMonth, AccountNumber) " & _
"VALUES('" & Me.Store & "', '" & Me.FiscalYear & "','" & Me.FiscalMonth & "', '1002' ) ;"

CurrentDb.Execute strSQL
strSQL = "INSERT INTO Budget (Store, FiscaLYear, FiscalMonth, AccountNumber) " & _
"VALUES('" & Me.Store & "', '" & Me.FiscalYear & "','" & Me.FiscalMonth & "', '1003' ) ;"

CurrentDb.Execute strSQL
strSQL = "INSERT INTO Budget (Store, FiscaLYear, FiscalMonth, AccountNumber) " & _
"VALUES('" & Me.Store & "', '" & Me.FiscalYear & "','" & Me.FiscalMonth & "', '1004' ) ;"

CurrentDb.Execute strSQL
strSQL = "INSERT INTO Budget (Store, FiscaLYear, FiscalMonth, AccountNumber) " & _
"VALUES('" & Me.Store & "', '" & Me.FiscalYear & "','" & Me.FiscalMonth & "', '1005' ) ;"

CurrentDb.Execute strSQL
Requery
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top