Results 1 to 15 of 15

Thread: [RESOLVED] Access 2002: adding multiple text boxes values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Resolved [RESOLVED] Access 2002: adding multiple text boxes values

    I am trying to create a survey input database. Guests fill out a survey. An employee inputs the data in a form. The information is numerical. I can make the information write to the table but I do not know how to make that information sum. Such as:

    Reservation Services has 3 questions. I want to be able to take the sum of all the survey's entered and give me the average.


    Can anyone help?

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Access 2002: adding multiple text boxes values

    If users enter the data in a textbox, the data will be text, not numeric, even if the text is a number. There are several functions you can use to convert text to numeric, such as Val, CInt, CDbl, CLng, depending on your needs. Probably better to avoid CInt, since the result of your average may not be an integer. Something like:
    VB Code:
    1. Set rs = db.OpenRecordset("SELECT fldFoo FROM [Reservation Services]")
    2. rs.MoveFirst
    3. Do While Not rs.EOF
    4.    total = total + CDbl(rs!fldFoo)
    5. Loop
    6. avg = total\rs.RecordCount
    Tengo mas preguntas que contestas

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Access 2002: adding multiple text boxes values

    Or use a SQL statement
    Code:
    SELECT 	AVG(YourField)
    FROM	YourTable
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: Access 2002: adding multiple text boxes values

    Dkenny,

    SELECT AVG(YourField) FROM YourTable
    The AVG(Yourfield) would that be the row names? Such as if the table name was tbltest and the field names was res1, res2, res3

    would it be
    Select AVG(res1!res2!res3)
    From tbltest

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: Access 2002: adding multiple text boxes values

    Salvelinus,

    You lost me on your first 2 lines of code.
    VB Code:
    1. Set rs = db.OpenRecordset("SELECT fldFoo FROM [Reservation Services]")
    2. rs.MoveFirst

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Access 2002: adding multiple text boxes values

    Sorry, I though you wanted the average down a column (field) rather than across a row (record).

    To get the average across a row you would add the following calc to a SQL statement
    ((res1 + res2 + res3)/3)

    e.g.
    Code:
    SELECT 	SurveyID (or some other field)
    	,more fields....
    	,(res1 + res2 + res3)/3 as 3QuestionAverage
    FROM	YourTable
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Access 2002: adding multiple text boxes values

    The SQL will work if the field is numeric, but it sounded like it was text.
    jmh, that was just a code sequence. db = a declared instance aof the database, rs is a recordset.
    VB Code:
    1. Dim db as DAO.Database
    2. Dim rs as DAO.Recordset
    3. Dim total as Double, avg as Double
    4. Set db = CurrentDB
    5. '...then the rest of the code
    although I did make the same assumption as DKenny, my example averages averages a field, not a record.
    Tengo mas preguntas que contestas

  8. #8
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Access 2002: adding multiple text boxes values

    If they are text fields, you will just need to do a type conversion with the SQL statement.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: Access 2002: adding multiple text boxes values

    Actually you are both right.

    What I have to do is average the 3 questions on the first section. Then if there are 150 surveys take the value for the average add them together and devide that by the 150 so I get the total average of the section over all the survey data.


    example.
    If questions 1,2,3 answers are 3,4,5. 3+4+5=12/3=4 4 is the number I need. Then if there are 150 survets I need to take the final number on all of them to tell me over all what I am looking for.

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Access 2002: adding multiple text boxes values

    You don't need to worry about how mant surveys there are if you use a SQL statement to calculate the Grand Average.

    Code:
    SELECT 	AVG((res1 + res2 + res3)/3) as GrandAvg
    FROM	YourTable
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: Access 2002: adding multiple text boxes values

    I can do this which ever way makes it easier. I havnt gotten to far into the process that I can not start all over.

    If you can give me some recomendations as to the best way to input this data (ie type of field. ATM I am using text boxes for entery) I can start anew.

  12. #12
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Access 2002: adding multiple text boxes values

    I'd use DKenny's SQL, using CDbl on the res1, res2 and res3 values if the value is text.
    You'll still have to open a recordset to get the value, but you won't have to do the calculation separately. My example uses DAO, which is slightly faster as long as everything's in Access. You could use ADO, which seems more common.
    Last edited by salvelinus; Jun 30th, 2006 at 09:37 AM.
    Tengo mas preguntas que contestas

  13. #13
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Access 2002: adding multiple text boxes values

    If the fields are storing numeric values that don't contain decimals, that I would suggest that you make the fields
    INT or BIGINT in SQL Server
    or
    Number in Access with a Fields Size of Integer or Long Integer
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  14. #14
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Access 2002: adding multiple text boxes values

    Would there be a problem using integers for the value if the average ends up a double?
    Tengo mas preguntas que contestas

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    128

    Re: Access 2002: adding multiple text boxes values

    Thanks again guys,

    I am going to start playing with this again. Will post again if I run into any troubles.


    Have a great day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width