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 May 22nd, 2006, 07:42 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
Unhappy VBA running sum needed by group

well, i have officially gone crazy over this.

Overall, i needed to obtian a Running Sum for each group in my query results or a count starting at 1 and increasing by 1 dependant on the amount results each employee has.

After searching the previous posts ("how to create a table in ms access db using vb code?" dated Oct 26, 2004) which is very close to what i need but i am having trouble converting his code to work for my needs.

Keep in mind that I am very new to VBA, therefore, this is a mix and match attempt at getting where i need to be. In other words, I could be in the wrong direction so please feel free to scratch whatever.

Any assistance is GREATLY APPRECIATED.

Code:
Public Function ProdLineUp()
Dim rsEmployee As Recordset, rsUpdate As Recordset
Dim qdf As QueryDef
Dim X As Integer
Dim strSQL As String

'pulls all employees that require a running tally by Production
Set rsEmployee = CurrentDb.OpenRecordset("qry_Downtime_Limited_Count_Employee")
rsEmployee.MoveLast
rsEmployee.MoveFirst

'contains all desired fields EXCLUDING running tally
Set qdf = CurrentDb.QueryDefs("qry_Update")


For X = 1 To rsEmployee.RecordCount
    qdf.Parameters(0) = rsEmployee.Fields("Last_Name")
    Set rsUpdate = qdf.OpenRecordset


'this is where i need to located the running tally...possibly using dsum function with default=1 and if recordsetcount>1 then recordset count +1 ?????
     
    

'then i need to update all info from "qry_Update" plus the newly created running tally into tbl_Downtime_Production_Count
    
    DoCmd.RunSQL "INSERT INTO tbl_Downtime_Production_Count SELECT Last_Name as Last_Name, Production_Name as Production_Name, PurposedStartDate as PurposedStartDate, PurposedEndDate as PurposedEndDate, " ' & X & '" as FASProdLineUp) " _
    & "FROM qry_Update;"
    
    rsUpdate.Close
    rsEmployee.MoveNext
Next X
    
Set rsUpdate = Nothing
Set rsEmployee = Nothing
Set qdf = Nothing

MsgBox "Update Complete"
End Function






tuk

Last edited by tuktuk : May 23rd, 2006 at 08:25 PM. Reason: Found previous threads that pointed in diff direction

Reply With Quote
  #2  
Old May 23rd, 2006, 08:43 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
told you i was going crazy....the correct reference that matches what i am trying to do is "SQL 'insert into' in vba query not updating table "

tuk

Reply With Quote
  #3  
Old May 26th, 2006, 07:11 AM
hithere's Avatar
hithere hithere is offline
Learner
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: India
Posts: 450 hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level)hithere User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 12 h 13 m 21 sec
Reputation Power: 18
What error u r getting????
__________________
Do, or do not. There is no 'try'.

Reply With Quote
  #4  
Old May 26th, 2006, 12:27 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
a run time error on the 'insert into' statement. i want to say it has to do with the ""&X&'".

thanks for the help

Reply With Quote
  #5  
Old May 26th, 2006, 12:37 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
I can also create a update query to a table, say [tbl_increment] with a Primary Key set to incrementing for EmployeeOne. Then create another update query to pull all of [tbl_increment] including the primary key field/'assignment count' (the desired info) to a 2nd table, called [tbl_increment_combined]. the delete [tbl_increment] and repeat the procedure for EmployeeTwo?

this would entail having a vba code to delete the old table, say for employee one and create a new for employee two and repeat the procedure until end of employee but the coding for that is completely beyond me.

can anyone figure this one out? i am game for what ever is easiest.

Tuk

Reply With Quote
  #6  
Old May 26th, 2006, 03:18 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
here is my attempt at creating the table and deletign the table...keep in mind i need to add the recordset count and loop in CreateTable(). I am currently unable to create the table...it is erroring on "cmd.execute"; syntax error

Private Sub CreateTable()
Const strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\my documents\mdb1.mdb;Persist Security Info=False"
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = strConnection
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "create table tbl_Increment (a autonumber, b varchar(20))"
cmd.Execute
cnn.Close
End Sub



Private Sub DeleteTable()
DoCmd.SetWarnings False
'this just deletes that data in the tbl_Increment.
'i need VB code that removes the entire tble so that the next time CreateTable() is ran the autonumber field will start at "1".
DoCmd.OpenQuery "DELETEQUERY", acViewNormal, acEdit
DoCmd.SetWarnings True
End Sub

Reply With Quote
  #7  
Old May 26th, 2006, 07:13 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
well, i have figured out how to create the table.

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = strConnection
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "create table tnn1 (a number, b varchar(10))"
cmd.Execute
cnn.Close

jsut like the string said....my bad.

will auto create a table with a AutoNumber field? my test indicate no.

also i tried using for following to delete the table but no go. can you see how to fix it?

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = strConnection
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "delete table tnn1 (a number, b varchar(10))"
cmd.Execute
cnn.Close

Reply With Quote
  #8  
Old May 27th, 2006, 02:47 AM
pmlakshmis pmlakshmis is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 21 pmlakshmis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 7 m 47 sec
Reputation Power: 0
pmlakshmis

Quote:
Originally Posted by tuktuk
well, i have figured out how to create the table.

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = strConnection
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "create table tnn1 (a number, b varchar(10))"
cmd.Execute
cnn.Close

jsut like the string said....my bad.

will auto create a table with a AutoNumber field? my test indicate no.

also i tried using for following to delete the table but no go. can you see how to fix it?

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = strConnection
cnn.Open
cmd.ActiveConnection = cnn
'$$$$$$$$$$$$
cmd.CommandText = "delete * from table"
'$$$$$$$$$$$
cmd.Execute
cnn.Close



'query to create sum of particular field
'$$$$
rs.open " select sum(no) from table_name group by name ",cnn,1,3
'$$$$$
msgbox rs.recordcount ' this would give u the record count
'$$$$$

Reply With Quote
  #9  
Old May 30th, 2006, 08:22 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
i would like to have an autonumber associated with each line item rather than a summation.

therefore, i have a new table being created using code from a previous string:
Const strConnection As String = 'database location
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
cnn.ConnectionString = strConnection
cnn.Open
cmd.ActiveConnection = cnn
cmd.CommandText = "create table tnn1 (a number, b text)"
cmd.Execute
cnn.Close
End Sub

how can i change the "data type" for the newly created table to be a Primary Key or an field with a Autonumber setting?

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VBA running sum needed by group


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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





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