VBA SQL Inert into Select No Error but not working

Clete

Board Regular
Joined
Sep 5, 2014
Messages
62
The line DoCmd.RunSQL "INSERT INTO TotalInterest (FileNo, TotInt) SELECT FileNumber, NewTotalInterest FROM TotalInterestQuery" The code runs without any errors but its not inserting the record from the query into the the table total interest query. Any help would be greatly appreciated this one procedure has been holding up a project for nearly a week now.


Private Sub Form_Open(Cancel As Integer)
Dim maxDate As Date
maxDate = DMax("SystemDate", "SystemDate")
If maxDate = Date Then
Else
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO SystemDate (SystemDate) VALUES (Date());"

DoCmd.OpenQuery ("Daily Interest")
DoCmd.OpenQuery ("TotalInterestQuery")

DoCmd.RunSQL "DELETE * FROM TotalInterest"
DoCmd.RunSQL "INSERT INTO TotalInterest (FileNo, TotInt) SELECT FileNumber, NewTotalInterest FROM TotalInterestQuery"
DoCmd.Close acQuery, "Daily Interest"
DoCmd.Close acQuery, "TotalInterestQuery"
DoCmd.SetWarnings True
End If
End Sub​
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Not sure I get it...

DoCmd.RunSQL "DELETE * FROM TotalInterest" <<<You just deleted everything from here
DoCmd.RunSQL "INSERT INTO TotalInterest (FileNo, TotInt) SELECT FileNumber, NewTotalInterest FROM TotalInterestQuery" <<<But I imagine it's in this query so what records would it be appending?
 
Upvote 0
I delete the records from the total interest table because it has the total interest amount from the day before. At this point the TotalInterestQuery has already calculated the total interest for the day of and those are those are the records im trying to insert into the interest table which is now empty.
 
Upvote 0
Re: VBA SQL Inert into Select No Error but not working (Commented Out Set Warnings to False)

When I debug this and step through... even though my query TotalInterestQuery has 2 records that I want to insert into the now empty Total Interest Table it says trying to append 0 records yes or no?
 
Upvote 0
Re: VBA SQL Inert into Select No Error but not working (Commented Out Set Warnings to False)

What's the entire message? What happens if you run that APPEND query on its own?
 
Upvote 0
Re: VBA SQL Inert into Select No Error but not working (Commented Out Set Warnings to False)


Is there a way to just replace the contents of the table? Instead of adding the records to whats already there.

I see whats happening... once i delete the records from the total interest table and run the Insert into line its rerunning the Total Interest Query. The problem with that is the Total Interest Query uses the value in the total interest table to calculate current interest and now it's empty so I have 0 records after the insert into line runs.

How can I just replace the contents of the table with the results of the query? If I don't delete the contents of the total interest table I get a primary key violation. I then added record number as the primary key to get around this but the insert into statement adds the 2 records to the 2 records already there and I need them replaced.​
 
Upvote 0
Re: VBA SQL Inert into Select No Error but not working (Commented Out Set Warnings to False)

Hmm, a little confusing what you said there but perhaps an UPDATE query if you are just looking to replace data in specific fields and not actually the whole record.
 
Upvote 0
Re: VBA SQL Inert into Select No Error but not working (Commented Out Set Warnings to False)

Ill need to replace the whole record because some days the TotalInterestQuery will have new accounts that aren't already in the TotalInterest table.
 
Upvote 0
Re: VBA SQL Inert into Select No Error but not working (Commented Out Set Warnings to False)

Then my only suggestion would be is to adjust the query till you get only what you want to append. This might required doing a variation on an find unmatched results.
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,539
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top