Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    weekday counter

    Nothing seems to be working today so I apologise for the frequency of questions on here.



    I've been looking at the following two links:

    https://msdn.microsoft.com/en-us/lib...or=-2147217396
    https://msdn.microsoft.com/en-us/lib...ffice.12).aspx

    I've tried to use the first one in a test environment and all I get back is #name?

    nothing I try generates a result. How can I troubleshoot this further? I've checked all the names are correct and changed some test data so far. I don't know what else to try.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I've tried to use the first one in a test environment and all I get back is #name?
    That usually means that it is unable to find the User Defined Function you are calling.
    Where exactly are you placing the VBA code for the User Defined Function? In which Module?
    Them, please post the formula you are creating that is trying to use it.

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    location: My new app > modules > work_days.
    Name: Work_days

    Code:
    Code:
    function Work_Days(BegDate As Variant, EndDate As Variant) As Integer
     
     Dim WholeWeeks As Variant
     Dim DateCnt As Variant
     Dim EndDays As Integer
     
     On Error GoTo Err_Work_Days
     
     BegDate = DateValue(BegDate)
     EndDate = DateValue(EndDate)
     WholeWeeks = DateDiff("w", BegDate, EndDate)
     DateCnt = DateAdd("ww", WholeWeeks, BegDate)
     EndDays = 0
     
     Do While DateCnt <= EndDate
     If Format(DateCnt, "ddd") <> "Sun" And _
     Format(DateCnt, "ddd") <> "Sat" Then
     EndDays = EndDays + 1
     End If
     DateCnt = DateAdd("d", 1, DateCnt)
     Loop
     
     Work_Days = WholeWeeks * 5 + EndDays
     
    Exit Function
     
    Err_Work_Days:
     
     ' If either BegDate or EndDate is Null, return a zero
     ' to indicate that no workdays passed between the two dates.
     
     If Err.Number = 94 Then
     Work_Days = 0
     Exit Function
     Else
    ' If some other error occurs, provide a message.
     MsgBox "Error " & Err.Number & ": " & Err.Description
     End If
     
    End Function

    control source of textbox on form: =Work_Days([first],[second])

    this is different code again from the two links I posted earlier but the situation is the same.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I re-created it on my side, and it seems to work for me.
    If you go to your VB Editor and click "Compile" under the "Debug" menu, do you get any errors?

    One option you can do is upload your database for analysis. I can't download it from my current location (but can later tonight or others may jump in and help).
    If you do that, just be sure to remove any sensitive data first.

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    My New App.zip

    I cant click compile. I'm sure its me being stupid doing something wrong. I just cant see what it is. If you're able to tell me what's wrong that would be great. (no rush ill be out the office till Monday soon enough)

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    OK. One more quick thing to check (if you cannot Compile).
    Are Macros/VBA enabled on your computer?
    If not, I could see how you are getting these type of errors.

  7. #7
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Yes mate, although I don't know how to check; I use them all the time with no issue.

    Thanks for the responses so far.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    What is name of the module?

    Function and module cannot have the same name.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yep, June hit it on the head. Your Module and Function are named the same thing. I changed the name of your module to "Module2" and it worked like a charm!

  10. #10
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    to be honest I don't know the difference but thanks for the answer. Ill change it and see

  11. #11
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Sorted! I could have sworn I tried it before I changed the name though. Anyways, thanks!

    Is there a way to apply this to a table rather than a form?

    It returns the value I need in the form, but I want to keep this information in a field in the table. So either I return values directly to the field (which makes more sense to me). Or I have the data moved on an event. What would you suggest?
    Last edited by Homegrownandy; 09-28-2015 at 03:38 AM.

  12. #12
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    One should never store values which can be calculated in a table - it goes against the Rules of Normalization and can ruin database integrity.
    Newer version of Access allow you to do calculations in a table, but other relational database programs (like SQL do not), because it goes against the nature of relational databases.

    You can do the calculations in a query, and base your Forms/Reports on those queries.

  13. #13
    Mahendra1000 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    101
    Dear Andy,

    Few months back I got the same problem and had a discussion over here with few experts and I got the answer "NO". This is the reason I was explained "We should not store the calculated values from form to table as it is against the Normalization rules and we need to calculate it in query whenever we need it."

    Thanks

  14. #14
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Okay I appreciate your answers, but this leads me to another potential problem. I want events to happen based on the number generated.

    The number represents how many working days notice we were given for cancelations. If its 1 we charge for the day and if its 2 we charge for half a day. Anything more than 2 wont have a charge.

    If it needs to have a charge applied I would want the database to apply that charge automatically. Currently we spend a long time looking through history of jobs (from several spreadsheets) to accumulate the costs. I see this as wasted time and I want to eliminate it as much as possible.

    Suggestions appreciated.

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Whether or not to show the charge would be another calculation.

    I have a db that violates many 'rules'. It is for processing laboratory test data. The calculations in the db are a convenience so the techs don't have to do manual calcs. We save the calc results to table. The primary purpose of this db is to publish the results to a report for distribution. Essentially, results become the 'raw' data. We do very little actual analysis of the data, just publish it. We don't want the results to be altered if test formula is modified. Rarely happens but there are constants in formulas that get recalibrated periodically and that can also alter results. Simplest solution for us is to save the calc.

    However, none of these calcs are aggregations of records. I have always advised to never save aggregate calcs.

    My point is, in my view it is a balancing act between normalization and ease of data entry/output.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. How do I go back to previous weekday?
    By bigspace55 in forum Queries
    Replies: 2
    Last Post: 01-29-2013, 10:56 AM
  2. Business Weekday?
    By HMEpartsmanager in forum Queries
    Replies: 2
    Last Post: 10-01-2012, 01:28 PM
  3. Help with Weekday Function
    By Juan4412 in forum Queries
    Replies: 3
    Last Post: 10-18-2011, 07:14 AM
  4. Weekday Name from a Date
    By Coors in forum Queries
    Replies: 9
    Last Post: 09-26-2011, 03:08 PM
  5. Weekday excluding weekends
    By jd316632 in forum Queries
    Replies: 3
    Last Post: 05-24-2010, 02:01 PM

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