473,503 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

recordset and combo box issues

121 New Member
Hi,

Bare with me this is going to take some explaining and any help is much appreciated

I have a form that stores details of sessions which include start/end date start/end time these sessions are associated with a project so you will have ten sessions associated to a project for example within the form i also have a session type dropdown so there are several different types of sessions that the user can chose from... so the important fields are as follows

ProjID
StartDate
EndDate
StartTime
EndTime
SessTypeID

What i need to do is is sum the total number of hours of a session type with the project ID

I have a query which points to the ProjectID and the sessionTypeID see below

Expand|Select|Wrap|Line Numbers
  1. SELECT T_ActiveSession.SessionID, T_ActiveSession.ProjID, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_ActiveSession.SessTypeID, DateDiff("n",[startdate]+[starttime],[enddate]+[endtime]-[break]-[downtime]) AS Expr1, T_ActiveSession.SessComplete, T_ActiveSession.Downtime, T_ActiveSession.Break, T_ActiveSession.StartDate, T_ActiveSession.EndDate
  2. FROM T_ActiveSession
  3. GROUP BY T_ActiveSession.SessionID, T_ActiveSession.ProjID, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_ActiveSession.SessTypeID, T_ActiveSession.SessComplete, T_ActiveSession.Downtime, T_ActiveSession.Break, T_ActiveSession.StartDate, T_ActiveSession.EndDate
  4. HAVING (((T_ActiveSession.ProjID)=SubFormFieldValue("F_ClientDetails","SF_Session","ProjID")) AND ((T_ActiveSession.SessTypeID)=SubFormFieldValue("F_ClientDetails","SF_Session","sesstypeid")))
  5. ORDER BY T_ActiveSession.SessTypeID;
  6.  
I then run a recordset on that query which totals up the number of hours that have been completed for session type1 within project1 for example

so there could be 10 records for session type 1 on various different days and session lengths within project1

the recordset below totals the number of hours worked on a session type 1
and then writes that value to a table.

The problem i have is when a user goes back to a previously saved record and tries to change the session type from session type1 to session type2 for example it sums the total number of hours for session type2 i need to be able to subtract the hours from session type1 in the table

hope my ramblings make sense

regards Phill

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim dbsCurrent As Database
  3.     Dim dbsLinkedData As Database
  4.     Dim rstQAssignedHrsSum As dao.Recordset
  5.     Dim rstTblAssignHrs As dao.Recordset
  6.     Dim strSeekProjID As String
  7.     Dim strSeekSessionID As String
  8.     Dim nullvalue As Variant
  9.     Dim rstExpr1 As String
  10.     Dim SumOfHrs As Integer
  11.     Dim HrsStore As Integer
  12.     Dim HrsTotal As Integer
  13.     Dim rstProjID As Integer
  14.     Dim rstSessTypeID As Integer
  15.     Dim rstCompletedHrs As Variant
  16.     Dim varbookmark As Variant
  17.     Dim TableAssignhrs As Integer
  18.     Dim SessTypeStore As Integer
  19.  
  20.  
  21.  
  22.   'sets quer recordset and the the table where the data is going to be written
  23.  
  24.     Set dbsCurrent = CurrentDb
  25.     Set dbsLinkedData = DBEngine.OpenDatabase("C:\Database\ClientBooking\ExampleAccess2000")
  26.     Set rstTblAssignHrs = _
  27.         dbsLinkedData.OpenRecordset("T_AssignHours", dbOpenTable)
  28.     Set rstQAssignedHrsSum = _
  29.       dbsCurrent.OpenRecordset("Q_SFormTotalHrs1", dbOpenDynaset)
  30.  
  31.  
  32.     strSeekProjID = Forms![F_ClientDetails]![SF_Session].Form![ProjID]
  33.     strSeekSessionID = Forms![F_ClientDetails]![SF_Session].Form![SessTypeID]
  34.  
  35. With rstQAssignedHrsSum
  36.  
  37. Do
  38. ' loops round and totals up hours ready to be written to table
  39. Do Until rstQAssignedHrsSum.EOF
  40.  
  41.  
  42.         rstExpr1 = rstQAssignedHrsSum!expr1
  43.         HrsStore = HrsStore + rstExpr1
  44.  
  45.         .MoveNext
  46.         HrsTotal = HrsTotal + HrsStore
  47.         HrsStore = 0
  48.  
  49. Loop
  50.  
  51. Loop Until rstQAssignedHrsSum.EOF
  52.  
  53.         .Close
  54.  
  55. End With
  56.  
  57. 'loops table until record is found and writes data to field
  58. With rstTblAssignHrs
  59.  
  60.     Do
  61.  
  62.     Do Until rstTblAssignHrs.EOF
  63.  
  64.  
  65.         rstProjID = rstTblAssignHrs!projectID
  66.         rstSessTypeID = rstTblAssignHrs!SessTypeID
  67.  
  68.  
  69.      If rstProjID = strSeekProjID And rstSessTypeID = strSeekSessionID Then
  70.  
  71.         rstTblAssignHrs.Edit
  72.  
  73.  
  74.         rstTblAssignHrs!completedHrs = HrsTotal
  75.         rstTblAssignHrs.Update
  76.  
  77.         End If
  78.  
  79.         .MoveNext
  80.  
  81.     Loop
  82.  
  83. Loop Until rstTblAssignHrs.EOF
  84.  
  85.         .Close
  86.  
  87.     End With
  88. 'Exit_Command16_Click:
  89.  
  90.  Exit Function
  91. 'Err_Command16_Click:
  92.  
  93.   '  MsgBox Err.Description
  94.   '  Resume Exit_Command16_Click
  95. Exit Function
  96. End Function
  97.  
Jan 23 '09 #1
4 1673
DonRayner
489 Recognized Expert Contributor
the recordset below totals the number of hours worked on a session type 1
and then writes that value to a table.
Is there a paticular reason that you need to write this data to a table? You would be much better off using a query to calculate the totals as you require them. That way each time the query is run you would have a freshly updated set of totals.
Jan 23 '09 #2
NeoPa
32,557 Recognized Expert Moderator MVP
This seems a very straightforward problem (not sure why such complex explanation).

This illustrates the very common problem you get when you fail to use the database as a database and try to make it into a transaction processing system.

This issue is often referred to as Normalisation. Check out Normalisation and Table structures for a fuller explanation.
Jan 25 '09 #3
NeoPa
32,557 Recognized Expert Moderator MVP
By the way, it's possible to use Access as a transaction processing system. It's actually quite flexible that way, but as it's an RDBMS, and it gives you all that goes with that, you'd need a fairly good reason to want to go what is essentially the more difficult route.
Jan 25 '09 #4
phill86
121 New Member
Hi Neopa and DonRayner

I have found a solution

Thanks for your help
Jan 29 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3861
by: dixie | last post by:
I have a form full of subforms which bring summary information onto the form from about 12 different tables. I am trying to get all of that summary information (mainly numbers) into 1 large table...
0
2629
by: CFW | last post by:
I thought this was going to be easy but I'm missing something . . . I need to open an ADODB recordset using the recordset source for a list box on my for. When my form opens, the list box ADODB...
0
2337
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has...
2
1416
by: airman_30 | last post by:
i am opening a recordset in my VB code and populating a combo box with the data from one of the fields in my recordset. I want to set it up so that, when a user selects one of the values from the...
2
4390
by: Laphan | last post by:
Hi All I know you will probably say that I should use MS SQL Server DBs with ASP, but my MySQL and ASP combo works and is affordable for me and up until now didn't give me any grief until...
2
4787
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
4
2779
by: Kev | last post by:
Hello, I have an Access 2003 database running on an XP network. I have a datasheet subform containing a 28 day roster - shift1 to shift28. Each record has 1 RosterEmpID, 1 EmployeeNumber, 28...
2
10436
by: Tom Clavel | last post by:
Scratching my head. I am using the filter property on a combo box .AfterUpdate event to get to a single client record. This is causing a some strange behavior: As I enter a subform, I get a no...
1
1892
by: omar.norton | last post by:
I am trying to create a from with a series of combo boxes that each query a different field (called Specific01, Specific02 etc., except the first field which is called Condition). Each combo box...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.