Results 1 to 13 of 13
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    run-time errror '13 on forms on open event

    Hi Guys



    i am getting a run-time errror '13' when this code run on a forms on open event

    Dim PreplannedCapacity As string
    PreplannedCapacity = Nz(DSum("PrePlannedCapacity", "UNEXAreaCapacityPrePlan", "Area = '" & Forms!UNEXCapacitys!Process & "'" And "WeekNumber = #" & Forms!UNEXCapacitys!DATE & "#"), 0)


    Me.Text12 = PreplannedCapacity
    End Sub

    any ideas how i can sort this,

    many thanks

    Steve

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try running it in the On Load event instead.

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi RuralGuy

    i get the same error their also.

    PrePlannedCapacity = number
    UNEXAreaCapacityPrePlan = table name
    Area =text
    Forms!UNEXCapacitys!Process = text field
    WeekNumber =is a number

    above is what each part of the code is could it be an issue with the dim type? sorry if my terminalogy is wrong

    steve

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is this running in the UNEXCapacitys form?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your dsum() function will return a number, not a string.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This does not look right either:
    "Area = '" & Forms!UNEXCapacitys!Process & "'" And "WeekNumber = #"
    I believe it should be:
    "Area = '" & Forms!UNEXCapacitys!Process & "' And WeekNumber = #"

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728
    Is "PrePlannedCapacity" really a field in table "UNEXAreaCapacityPrePlan"?

    I think you have an issue with double quote in your expression:

    PreplannedCapacity = Nz(DSum("PrePlannedCapacity", "UNEXAreaCapacityPrePlan", "Area = '" & Forms!UNEXCapacitys!Process & "'" And "WeekNumber = #" & Forms!UNEXCapacitys!DATE & "#"), 0)

    I would try (untested):

    PreplannedCapacity = Nz(DSum("PrePlannedCapacity", "UNEXAreaCapacityPrePlan", "Area = '" & Forms!UNEXCapacitys!Process &
    "' And WeekNumber = #" & Forms!UNEXCapacitys!DATE & "#"), 0)

    Good luck.


    OOops: I see Allan has responded while I was interrupted with a Skype call. You're going to need to reconcile your data types.
    Last edited by orange; 01-20-2016 at 07:52 AM. Reason: spelling

  8. #8
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Ruralguy

    i have changed the code as you recommended, i now get the erro "Run-time error '3075': Systntax error in date in query expression 'Area ='KDM' And WeekNumber =#4'

    i will keep trying

  9. #9
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Orange

    sorry i did not see your reply untill i posted back.

    im sure im doing something really silly but at the moment i just can't see it, i will plod on and hopefully get my head around it

    Steve

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728
    Hmmm?
    If PrePlannedCapacity is a number then you do NOT need to enclose in quotes.
    I would call the control by a different name to avoid confusion, For example, txtPrePlannedCapacity if it is a text/string, or intPrePlannedCapacity or dblPrePlannedCapacity (or similar) if it was a number. I'm not sure how you are getting week number from a date. See this for the Datediff() function
    Perhaps you should show us your table definition to see field names and data types. And a description of exactly what you are trying to do in plain English.

    Good luck with your project.

  11. #11
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Orange

    sorry for the late reply,

    not sure why but when i changed the code to this PreplannedCapacity = Nz(DSum("PrePlannedCapacity", "UNEXAreaCapacityPrePlan", "Area = '" & Forms!UNEXCapacitys!Process & "' And WeekNumber = #" & Forms!UNEXCapacitys!DATE & "#"), 0)

    as advised i was getting the error message above, when i made a new blank form and copied the code onto it it worked as expected!!!


    not sure why but it was sure getting worring

    any way alls working now sorry for not getting back sooner, been a manic day

    Kind regards

    Steve

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,728

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thanks for posting back with your success and solution. Be sure to mark this thread as Solved.

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

Similar Threads

  1. Setting an event at a certain time
    By QuantifyRisk in forum Forms
    Replies: 3
    Last Post: 05-27-2015, 10:02 AM
  2. Replies: 5
    Last Post: 04-11-2015, 03:54 AM
  3. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  4. time and Date open the forms
    By mathanraj76 in forum Programming
    Replies: 3
    Last Post: 05-07-2013, 01:35 AM
  5. runtime errror 3075
    By Compufreak in forum Access
    Replies: 8
    Last Post: 01-15-2013, 04:36 AM

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