Results 1 to 4 of 4
  1. #1
    chims is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    2

    Question Performing Calculations with Recordsets

    Hi,

    I am currently trying to create a simple form that is dummy proof to update associates vacation time. However, the code is receiving a compile error: Sub or Function not defined when ran. I have 2 combo box's and one text box on the form.



    Please any ideas!?

    Code:
    Dim rst As Recordset
    Set rst = CurrentDb.OpenRecordset("Tbl_Associate", dbOpenDynaset)
    rst.FindFirst "[NBKID] = '[Forms]![Frm_UpdateAssociatesTime]![comboNBK]'"
    rst.Edit
    If [Forms]![Frm_UpdateAssociatesTime]![Combo6] = "Vacation" Then
        
        rst![Current Vacation Available] = Sum(rst![Current Vacation Available] - [Forms]![Frm_UpdateAssociatesTime]![Text14])
        rst![Vacation Used] = Sum(rst![Vacation Used] + [Forms]![Frm_UpdateAssociatesTime]![Text14])
        rst.Update
    
    End If
    rst.Close
    
    Set rst = Nothing

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You dont need code, nor recordsets to a combo data.
    put the SQL in a query, and assign the query to the combo.rowsource.

    IF assigning a data value to a textbox , use a query and give it =Dlookup() , or DCount() in field.

    No code needed.

  3. #3
    chims is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    2
    Seems alot easier lol.

    Will that still work if I am trying to do calucations depending on the selection of [Forms]![Frm_UpdateAssociatesTime]![Combo6]? There are a possible of 3 selections (Vacation, Sick, Personal) and each one has their own field totals on Tbl_Associate.

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    1. you should name your controls so they are readily understandable.. not combo6 (default name), but in the control property, other tab, name,
    give it say cboVacaType, or lstStates, etc.


    2. Your query would pull data based on the selection of combo6.

    select * from tbl_associate where [vacaType] = '" & [Forms]![Frm_UpdateAssociatesTime]![Combo6] & "'"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Performing calculations in a form
    By Demerit in forum Forms
    Replies: 9
    Last Post: 12-12-2013, 10:54 AM
  2. Performing calculations from a drop down list
    By snowdrop in forum Queries
    Replies: 5
    Last Post: 01-11-2012, 06:39 AM
  3. Performing calculations in the form.
    By mulefeathers in forum Forms
    Replies: 4
    Last Post: 12-07-2011, 10:47 AM
  4. Performing count in VBA
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 08-21-2010, 07:41 PM
  5. Replies: 14
    Last Post: 06-03-2010, 06:03 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums