Results 1 to 5 of 5
  1. #1
    ch5150 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2014
    Location
    The Great Central Valley of California
    Posts
    17

    If Then / ElseIf Problem

    My code works to a point... As long as there are only 4 digits in the entry to update the field it works. However, if there are more or less than 4 digits in the entry to update the field [JobTotalFootage] then the response is wrong in [SetsPerHour] or it gives no response. Can someone help?




    Private Sub JobTotalFootage_AfterUpdate()
    If [JobTotalFootage] < "3000" Then
    [SetsPerHour] = "10"
    ElseIf [JobTotalFootage] < "7000" Then
    [SetsPerHour] = "6"
    ElseIf [JobTotalFootage] > "6999" Then
    [SetsPerHour] = "3"
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It appears you're trying to do a numerical comparison with a text value. What is the data type of JobTotalFootage? I would use a numeric data type, and not have any quotes around the values in the tests.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ch5150 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Nov 2014
    Location
    The Great Central Valley of California
    Posts
    17
    I changed the data type in the underlying table from text to number and removed the quotes around the three test values but left the return values in quotes in the code and it appears to work correctly. Thank you very much... I had a real rough day and it was nice to end it with at least a small victory. It may be that later as I develop this application that I may run up against this with the return values, but at least now I'll know where to look.
    Sincerely,
    ch5150

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    try not to use ELSEIF, use SELECT CASE , much easier to read / decode

    Code:
    
    
    Code:
    select case val([JobTotalFootage])
    case  < 3000
        [SetsPerHour] = "10"
    case < 7000
        [SetsPerHour] = "6"
    case > 6999
        [SetsPerHour] = "3"
    End select

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

Similar Threads

  1. Automate data input with If, Elseif Statement
    By Exmark1 in forum Programming
    Replies: 4
    Last Post: 02-19-2015, 09:52 AM
  2. If then Elseif then....
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 10-27-2014, 01:31 PM
  3. If ElseIf Not Working
    By theperson in forum Programming
    Replies: 5
    Last Post: 02-27-2013, 07:40 AM
  4. Help with ElseIf Statements
    By dshillington in forum Programming
    Replies: 6
    Last Post: 12-16-2011, 03:32 PM
  5. Easy one, If then ElseIf
    By Bruce in forum Forms
    Replies: 4
    Last Post: 12-01-2011, 12:44 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