Results 1 to 12 of 12
  1. #1
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57

    Runtime error 13 typing mismatc

    I am trying to verify if a site selected from a cascading combobox (named cboSite) matches the any of the varies site names in the column "within 10" in the table named SLA. if so i want it to calculate a functioni have come up with the code as show below but i get a runtime error and am not sure how to rectify this.




    Code:
    Private Sub txtRTF_Click()
    If (DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' ")) Then
    Me.txtRTF = DateDiff("hm", 0, 8, [Date Fault Lodged])
    End If
    End Sub

    The column type of the column Within10 in SLA table is short text

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    What is the Row Source property of cboSite
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Code:
    Me.txtRTF = DateDiff("hm", 0, 8, [Date Fault Lodged])
    What are you trying to do here?

    Datediff doesn't allow "HM"

    and 0 and 8 aren't dates?

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by andy49 View Post
    Code:
    Me.txtRTF = DateDiff("hm", 0, 8, [Date Fault Lodged])
    What are you trying to do here?

    Datediff doesn't allow "HM"

    and 0 and 8 aren't dates?
    Don't see that this is relevant. Perhaps you've posted a response to the wrong thread?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Sorry. Getting myself totally confused today.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Hehe. It happens bob


    Sent from my iPhone using Tapatalk

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by andy49 View Post
    Hehe. It happens bob


    Sent from my iPhone using Tapatalk
    Yes, but not sure why. I have noticed that the older I get the more frequently it happens
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If (DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' ")) Then
    In that statement, you are treating DLookup as if it returns a True / False. It doesn't - it returns a value if there is a record which matches the criteria, and it returns a Null otherwise.

    You need to handle that Null with a Nz, something like this:

    If nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "),"N/A") <> "N/A" Then

    So it will execute the me!txtRTF = ... only if the DLookup does not return a Null, and the Nz does not yield a "N/A"

  9. #9
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57
    Quote Originally Posted by Bob Fitz View Post
    What is the Row Source property of cboSite
    the row source proeperty is- SELECT [Site Query].[Site] FROM [Site Query];

  10. #10
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57
    Quote Originally Posted by andy49 View Post
    Code:
    Me.txtRTF = DateDiff("hm", 0, 8, [Date Fault Lodged])
    What are you trying to do here?

    Datediff doesn't allow "HM"
    and 0 and 8 aren't dates?
    the m was a typo it should have been n.
    i have a text box which automatically picks up date and time and dispalys it in the format mm/dd/yyyy hh:mm:ss Am/PM
    what i am trying to do is add 8 hours to the time displayed in the date fault lodged and show the result in txtRTF. i was experimenting with the datediff and diff2dates equation. the datediff function gives me an error. however the diff2 dates function works but not the way i want it to. this is the diff2dates equation.
    Code:
    =Diff2Dates("hn",0,8,[Date Fault Lodged])
    the result i get is 192 hours 0 minutes
    the reason i put a 0 before the 8 is because if i use this equation
    Code:
    =Diff2Dates("hn",8,[Date Fault Lodged])
    i get a result 1026570 hours 2 minutes
    i was able to figure a way to add 8 hours to the time
    Code:
    =Diff2Dates("hn",0,0.334,[Date Fault Lodged])
    i get the result 8 hours

    displaying 8 hours is ok but i am trying to dispaly the date and time
    eg date fault lodged - 2/1/2017 10:00:00 AM
    so in my txtRTF i want the result to be displayed 2/1/2017 6:00:00 PM

  11. #11
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57
    Quote Originally Posted by John_G View Post
    In that statement, you are treating DLookup as if it returns a True / False. It doesn't - it returns a value if there is a record which matches the criteria, and it returns a Null otherwise.

    You need to handle that Null with a Nz, something like this:

    If nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "),"N/A") <> "N/A" Then

    So it will execute the me!txtRTF = ... only if the DLookup does not return a Null, and the Nz does not yield a "N/A"
    thanks for the help. it did work well, i changed the date calculation equation and it still works fine
    Code:
    Private Sub txtRTF_Click()
    If Nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "), "N/A") <> "N\A" Then
    Me.txtRTF = DateAdd("h", 2, [Date Fault Lodged])
    End If
    End Sub
    i tried adding an else if statement i do not get an error however the elseif is not executed

    Code:
    Private Sub txtRTF_Click()
    If Nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "), "N/A") <> "N\A" Then
    Me.txtRTF = DateAdd("h", 2, [Date Fault Lodged])
    ElseIf (DLookup("10_50", "SLA", "10_50 = '" & Me.cboSite.Value & " ' ")) Then
    Me.txtRTF = DateAdd("h", 4, [Date Fault Lodged])
    ElseIf (DLookup("50_80", "SLA", "50_80 = '" & Me.cboSite.Value & " ' ")) Then
    Me.txtRTF = DateAdd("h", 8, [Date Fault Lodged])
    ElseIf (DLookup("80_100", "SLA", "80_100 = '" & Me.cboSite.Value & " ' ")) Then
    Me.txtRTF = DateAdd("d", 2, [Date Fault Lodged])
    ElseIf (DLookup("Over100", "SLA", "Over100 = '" & Me.cboSite.Value & " ' ")) Then
    Me.txtRTF = DateAdd("d", 10, [Date Fault Lodged])
    End If
    End If
    End Sub
    Last edited by joym; 02-15-2017 at 07:36 PM.

  12. #12
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If Nz(DLookup("Within10", "SLA", "Within10 = '" & Me.cboSite.Value & " ' "), "N/A") <> "N\A" Then
    In that statement, you have the slashes in opposite directions, so I'm not sure what the effect is. Change them both to "N/A" to see what happens.

    I think too that you should change all the DLookup's to use the Nz as well, checking for "N/A", because they all have the same problem with Null as your original one did.

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

Similar Threads

  1. Runtime error
    By nick243 in forum Programming
    Replies: 2
    Last Post: 05-18-2016, 09:05 AM
  2. Replies: 3
    Last Post: 02-26-2016, 12:34 PM
  3. Replies: 2
    Last Post: 08-22-2015, 11:26 AM
  4. Replies: 2
    Last Post: 10-15-2014, 04:23 AM
  5. Replies: 13
    Last Post: 06-12-2012, 09:52 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