Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 20th, 2005, 07:34 AM
Barn Barn is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 5 Barn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 41 sec
Reputation Power: 0
Question SQL 'insert into' in vba query not updating table

I am attempting to use VBA in access 2003 to run a SQL 'insert into' command. The SQL command is part of a loop such that the code updates with a variable string on each pass. The code runs and works, however when running over several passes the SQL does not update the required tables on all passes. However the code does update on some of the passes, if i run the VBA code again then a different set of passes are updated to the table by the SQL. The SQL takes about 2 minutes to run. The VBA is show below. How can i make the code write to the tables on each pass?

Private Sub Holding_Click()
On Error GoTo err

Dim i As String
Dim j As String
Dim a As String
Dim CON As ADODB.Connection
Dim rstWEEK As New ADODB.Recordset


Set CON = CurrentProject.Connection
CON.CommandTimeout = 0

rstWEEK.Open "week", CON, adOpenKeyset, adLockOptimistic

i = InputBox("Start week")
j = InputBox("End week")

rstWEEK.MoveFirst
Do Until rstWEEK!week = i
rstWEEK.MoveNext
Loop

DoCmd.RunSQL "delete tbl_summary"

exitloop2:

rstWEEK.MovePrevious
a = rstWEEK!week
rstWEEK.MoveNext
i = rstWEEK!week
rstWEEK.MoveNext
SysCmd acSysCmdSetStatus, i

DoCmd.RunSQL "insert into tbl_summary SELECT 'holding' as measure, '" & i & "' as data_week, week_num.year_week as year_week, year_number, week_number, SUM([tblOrderBookDetail~wk" & i & "].ACTUAL_SALE_VALUE - [tblOrderBookDetail~wk" & i & "].VAT_PAYABLE) AS value " _
& "FROM [tblOrderBookDetail~wk" & i & "] LEFT OUTER JOIN week_num ON [tblOrderBookDetail~wk" & i & "].Delivery_Date = week_num.date_number LEFT OUTER JOIN [tblOrderBookDetail~Wk" & a & "] ON [tblOrderBookDetail~wk" & i & "].SALE_ITEM = [tblOrderBookDetail~Wk" & a & "].SALE_ITEM AND [tblorderbookdetail~wk" & i & "].Reference_No = [tblOrderBookDetail~Wk" & a & "].Reference_No " _
& "WHERE ([tblOrderBookDetail~wk" & i & "].Reference_No IN (SELECT reference_no FROM [tblorderbookdetail~wk" & i & "] WHERE sale_item LIKE 'zzg%')) AND ([tblOrderBookDetail~Wk" & a & "].Reference_No IS NULL) AND ([tblOrderBookDetail~Wk" & a & "].SALE_ITEM IS NULL) " _
& "GROUP BY week_num.year_week, week_num.year_number, week_num.week_number;"

If i = j Then
GoTo exitloop1
Else
GoTo exitloop2
End If

exitloop1:

SysCmd acSysCmdRemoveMeter
rstWEEK.Close
CON.Close

MsgBox "Done"

err_exit:
Exit Sub

err:
MsgBox err.Description
GoTo err_exit
End Sub


Thanks
Barney

Reply With Quote
  #2  
Old June 20th, 2005, 08:13 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
I'd first remove the error trapping and see if any unexpected errors pop up.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old June 21st, 2005, 12:54 PM
Barn Barn is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 5 Barn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 41 sec
Reputation Power: 0
error trapping seemed to be fine, however the following link has resolved the problem


http://forums.aspfree.com/showthread.php?p=205000#post205000

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > SQL 'insert into' in vba query not updating table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT