Results 1 to 4 of 4
  1. #1
    xwnoob is offline Advanced Beginner
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    76

    How to compare amounts between input field and listbox?

    How do i compare a value for a input field against a value in a column in a listbox.



    This is my code but currently nothing happens. I want to make sure drawdownamt(input field ) does not exceed the list box's column 4 amount.

    Both are in the same form


    Code:
    Private Sub DrawdownAmt_BeforeUpdate(Cancel As Integer)
    If Me.DrawdownAmt > Me.ListFacility.Column(3) Then
    MsgBox ("WARNING:You have entered an amount larger than total amount!")
    Cancel = True
    Me.DrawdownAmt.Undo
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Is selection of item in listbox done first?

    Step debug, what value is shown for the listbox variable in the code?

    Refer to link at bottom of my post for tutorial on debugging techniques.
    Last edited by June7; 01-06-2012 at 01:16 AM.
    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.

  3. #3
    xwnoob is offline Advanced Beginner
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    76
    Edit: i want to select the 6th column so the code would be like this:

    Private Sub DrawdownAmt_BeforeUpdate(Cancel As Integer)
    If Me.DrawdownAmt > Me.ListFacility.Column(5) Then
    MsgBox ("WARNING:You have entered an amount larger than total amount!")
    Cancel = True
    Me.DrawdownAmt.Undo
    End If
    End Sub

    I forgot to mention the listbox is a cascaded listbox,where it displays info depending on another listbox.

    im trying to use the locals window or the immediated window to debug but i cant see any variable values? My code is not a macro so can it still be executed step by step??



    Edit: I tried storing the values into variables and it worked.....

    Dim ListFacility As Single
    Dim drawdwnamt As Single


    ListFacility = Me.ListFacility.Column(5)
    drawdwnamt = Me.DrawdownAmt


    If drawdwnamt > ListFacility Then
    MsgBox ("WARNING:You have entered an amount larger than total amount!")
    Cancel = True
    Me.DrawdownAmt.Undo
    End If


    however should i DIM the variables as single or doubles?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Review that debug tutorial. Look at the sections on Breakpoint and Stepping. When code pauses, hover cursor over variables (like the listbox reference) to see the value.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-25-2010, 09:03 AM
  2. Lookup Table For Listbox Input
    By ColPat in forum Access
    Replies: 1
    Last Post: 05-26-2010, 05:09 AM
  3. Replies: 1
    Last Post: 02-03-2010, 09:17 PM
  4. Quarterly Amounts
    By Brian62 in forum Queries
    Replies: 9
    Last Post: 10-16-2009, 02:18 PM
  5. Replies: 1
    Last Post: 02-26-2009, 11:31 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