Results 1 to 5 of 5
  1. #1
    SA10014321 is offline Novice
    Windows 10 Access 2003
    Join Date
    Dec 2015
    Posts
    2

    Database event macros

    I am building a database and I want to be able to enter booking hours into a form, the system calculate the total hours for that month on a specific account and if it goes above 100 stop the booking going through



    Can any one help please?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    in your form beforeupdate event you could use something like

    if dsum("hours","myTable","[Account]=" & me.txtaccount & " AND format(bookdate,'mmyyyy')=format(date(),'mmyyyy')) +me.txthours>100 then
    msgbox "too many hours"
    cancel=true
    end if

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In the acct table, you have a MaxHrs field, set to 100.

    In the entry form, when you enter the Acct (combo) this also pulls the Max.
    have a field that has the sum of past hrs entered. ... Dlookup("[sumOfHrs]","qsHrs1AcctMo")
    This query , qsHrs1AcctMo, reads the text boxes,month and acct to sum hrs.

    then every entry,check
    If txtHrs+txtSum < txtMax then
    SaveEntry
    else
    MsgBox "Max hrs reached."
    endif

  4. #4
    SA10014321 is offline Novice
    Windows 10 Access 2003
    Join Date
    Dec 2015
    Posts
    2
    Quote Originally Posted by Ajax View Post
    in your form beforeupdate event you could use something like

    if dsum("hours","myTable","[Account]=" & me.txtaccount & " AND format(bookdate,'mmyyyy')=format(date(),'mmyyyy')) +me.txthours>100 then
    msgbox "too many hours"
    cancel=true
    end if
    &


    • ranman256
      In the acct table, you have a MaxHrs field, set to 100.

      In the entry form, when you enter the Acct (combo) this also pulls the Max.
      have a field that has the sum of past hrs entered. ... Dlookup("[sumOfHrs]","qsHrs1AcctMo")
      This query , qsHrs1AcctMo, reads the text boxes,month and acct to sum hrs.

      then every entry,check
      If txtHrs+txtSum < txtMax then
      SaveEntry
      else
      MsgBox "Max hrs reached."
      endif
    • 12-03-2015, 05:01 AM
      Ajax
      in your form beforeupdate event you could use something like

      if dsum("hours","myTable","[Account]=" & me.txtaccount & " AND format(bookdate,'mmyyyy')=format(date(),'mmyyyy')) +me.txthours>100 then
      msgbox "too many hours"
      cancel=true
      end if

      Really sorry guys I am completely new at this I have one form which means requires you to book hours against each booking, I want the database to total the hours for the month on each account and then if the hours reaches more than 100 for that month then let me know I need to make the booking on the other account and if the other account is over 100 stop me making the booking at all for that month only. So far I have built the form and done queries that total the amounts on each account would be grateful if you could let me know a solution to this problem and forgive me as I dont understand the abbreviations yet?

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    both of us have provided solutions - we have used abbreviations/aliases because you haven't provided details like table and field names - so for example - myTable - what have you called yours? Substitute it. same goes for all the others

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

Similar Threads

  1. Using VBA or macros to build a database
    By Access_Novice in forum Access
    Replies: 11
    Last Post: 01-07-2015, 11:43 AM
  2. Capture an “Enable Macros” warning event
    By LindaRuble in forum Programming
    Replies: 1
    Last Post: 03-19-2013, 10:22 AM
  3. How to CLOSE Database in Macros
    By taimysho0 in forum Programming
    Replies: 2
    Last Post: 01-06-2012, 01:52 PM
  4. Split web database macros
    By dreday in forum Access
    Replies: 4
    Last Post: 11-29-2011, 02:55 PM
  5. Database that runs macros in another DB
    By BED in forum Programming
    Replies: 1
    Last Post: 10-01-2010, 11:20 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