Results 1 to 7 of 7
  1. #1
    hawkins is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    82

    Run-Time error '2465'

    I have been trying to write vba for conditionals but I got down three groupings and then it gets a Run-Time error '2465' which cant find the field but it worked before adding the third grouping. The code looks like:
    If [PhaseImbal] < 2 Then [AmpsKwAApr].BackColor = vbYellow
    If [PhaseImbal] > 2 Then [AmpsKWAApr].BackColor = vbRed
    If [PhaseImbal] = 8 Then [AmpsKWAApr].BackColor= vbWhite

    Then that is repeated 3 times with different AmpsKWAAPr's. The first 2 times it worked then the third it received that error. I was wondering how I can get it to recognize the field again and having three Then statements so I can only have 3 rows instead of 9. Any suggestions will be greatly appreciated!

    **changed up- now my question is:
    Ive actually changed it up completely, but I have another question. I finally just used a text box to obtain a value that i was getting that error from, AmpacityRefence. I am wanting to divide AmpacityReference by AmpsA and do conditions from there but I am not getting the correct values from the divisions I dont think. Here is my code I have:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)


    Dim AmpacA As Double
    Dim AmpacB As Double
    Dim AmpacC As Double

    AmpacA = Me![AmpacityReference] / [AmpsA]
    AmpacB = Me![AmpacityReference] / [AmpsB]
    AmpacC = Me![AmpacityReference] / [AmpsC]

    If AmpacA > 0.6699 And AmpacA < 0.90001 Then
    AmpsKWAL.BackColor = vbYellow
    ElseIf AmpacA > 0.9 Then
    AmpsKWAL.BackColor = vbRed
    ElseIf AmpacA < 0.67 Then
    AmpsKWAL.BackColor = vbWhite
    End If

    End Sub

    The AmpacB and AmpacC will just be used in replicated if elseif statements. Somethings going wrong with my division but I dont know how. All suggestions will help greatly!
    Last edited by hawkins; 08-19-2011 at 02:22 PM.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If [PhaseImbal] < 2 Then [AmpsKwAApr].BackColor = vbYellow
    If [PhaseImbal] > 2 and [PhaseImbal] <> 8 Then [AmpsKWAApr].BackColor = vbRed
    If [PhaseImbal] = 8 Then [AmpsKWAApr].BackColor= vbWhite

  3. #3
    hawkins is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    82
    Ive actually changed it up completely, but I have another question. I finally just used a text box to obtain a value that i was getting that error from, AmpacityRefence. I am wanting to divide AmpacityReference by AmpsA and do conditions from there but I am not getting the correct values from the divisions I dont think. Here is my code I have:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim AmpacA As Double
    Dim AmpacB As Double
    Dim AmpacC As Double

    AmpacA = Me![AmpacityReference] / [AmpsA]
    AmpacB = Me![AmpacityReference] / [AmpsB]
    AmpacC = Me![AmpacityReference] / [AmpsC]

    If AmpacA > 0.6699 And AmpacA < 0.90001 Then
    AmpsKWAL.BackColor = vbYellow
    ElseIf AmpacA > 0.9 Then
    AmpsKWAL.BackColor = vbRed
    ElseIf AmpacA < 0.67 Then
    AmpsKWAL.BackColor = vbWhite
    End If

    End Sub

    The AmpacB and AmpacC will just be used in replicated if elseif statements. Somethings going wrong with my division but I dont know how. All suggestions will help greatly!

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If AmpacA > 0.6699 And AmpacA < 0.90001 Then
    AmpsKWAL.BackColor = vbYellow
    ElseIf AmpacA > 0.9 Then
    AmpsKWAL.BackColor = vbRed
    ElseIf AmpacA < 0.67 Then
    AmpsKWAL.BackColor = vbWhite
    End If

    There are overlaps in your division

    it should be

    If AmpacA > 0.6699 And AmpacA < 0.90001 Then
    AmpsKWAL.BackColor = vbYellow
    ElseIf AmpacA >= 0.90001 Then
    AmpsKWAL.BackColor = vbRed
    ElseIf AmpacA <= 0.6699 Then
    AmpsKWAL.BackColor = vbWhite
    End If

  5. #5
    hawkins is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    82
    **It worked perfectly for about 10 minutes and I didnt changed anything involving the query or anything that is reference from the query and I get the run-time error again. I dont understand why I get this error after a bit because thats what happened before to me with my other ways to solve it.

    Thanks for the help, I stupidly switched the fields i divided by so i was alwyas getting over 0.9. Do you by any chance know how to make a If Else Statement outside the If ELSEIF statements? I Need to create a condition for nulls right off the bat so if AmpsA or Me![AmpacityReference] is null it just fill the backcolor white. I had received a null error when I tried to run it. I have altered the code some so heres what I have now:
    Dim AmpacA As Double
    Dim AmpacB As Double
    Dim AmpacC As Double

    AmpacA = [AmpsA] / Me![AmpacityReference]
    AmpacB = [AmpsB] / Me![AmpacityReference]
    AmpacC = [AmpsC] / Me![AmpacityReference]

    If AmpacA >= 0.67 And AmpacA <= 0.9 Then
    AmpsKWAL.BackColor = vbYellow
    ElseIf AmpacA > 0.9 Then
    AmpsKWAL.BackColor = vbRed
    ElseIf AmpacA < 0.67 Then
    AmpsKWAL.BackColor = vbWhite
    End If

    If AmpacB >= 0.67 And AmpacB <= 0.9 Then
    AmpsKWB.BackColor = vbYellow
    ElseIf AmpacB > 0.9 Then
    AmpsKWB.BackColor = vbRed
    ElseIf AmpacB < 0.67 Then
    AmpsKWB.BackColor = vbWhite
    End If

    If AmpacC >= 0.67 And AmpacC <= 0.9 Then
    AmpsKWC.BackColor = vbYellow
    ElseIf AmpacC > 0.9 Then
    AmpsKWC.BackColor = vbRed
    ElseIf AmpacC < 0.67 Then
    AmpsKWC.BackColor = vbWhite
    End If

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    Dim AmpacA As Double
    Dim AmpacB As Double
    Dim AmpacC As Double
     
    if isnull(me![ampacityreference]) then
         AmpsKWAL.BackColor = vbWhite
         AmpsKWB.BackColor = vbWhite
         AmpsKWC.BackColor = vbWhite
    else
         AmpacA = [AmpsA] / Me![AmpacityReference]
         AmpacB = [AmpsB] / Me![AmpacityReference]
         AmpacC = [AmpsC] / Me![AmpacityReference]
     
         If AmpacA >= 0.67 And AmpacA <= 0.9 Then
             AmpsKWAL.BackColor = vbYellow
             AmpsKWB.BackColor = vbYellow
              AmpsKWC.BackColor = vbYellow
         ElseIf AmpacA > 0.9 Then
             AmpsKWAL.BackColor = vbRed
             AmpsKWB.BackColor = vbRed
             AmpsKWC.BackColor = vbRed
         ElseIf AmpacA < 0.67 Then
             AmpsKWAL.BackColor = vbWhite
             AmpsKWB.BackColor = vbWhite
             AmpsKWC.BackColor = vbWhite
         End If
     End If

  7. #7
    hawkins is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    82
    Your a life saver! I ended up hopefully figuring out the Run-Time error as well. Instead of Me![AmpacityReference] I just used AMpacityReference. Thank you for your help, I truly appreciate it!

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

Similar Threads

  1. Error in Run Time
    By dongodu in forum Queries
    Replies: 5
    Last Post: 07-24-2011, 06:54 PM
  2. Not figuring out dlookup (RunTime 2465)
    By Gilligan in forum Access
    Replies: 10
    Last Post: 03-08-2011, 02:48 PM
  3. Replies: 2
    Last Post: 12-23-2010, 09:11 AM
  4. Replies: 2
    Last Post: 12-02-2010, 02:35 AM
  5. Run Time Error 424
    By ddog171 in forum Programming
    Replies: 3
    Last Post: 02-04-2006, 07:13 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