Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    mejia.j88 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Location
    california
    Posts
    228
    What do you mean by: Is it conceivable to have the values being tested in a table? The values I'm entering or the values I am testing against?
    i can definitely put hte values im testing agaisnt in a table; it will have to be queried because the cut type and size come from a table containing individual part numbers (a ton of part numbers).
    I'm not 100% sure i understand the method you are suggesting :-/




  2. #17
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,527
    I mean the values like 0.10825 in the first test. If you can get that from a table, you don't need all the code you have now. My entire checkmeasurements function might look like:

    Code:
        Dim VariableName As Double
        VariableName = ValueIGetFromTheTableSomehow
    
        If Val(Me.txtMeasurement1) > Val(VariableName) Then          'value comparison
            MsgBox ("Measurement entered is too large")         'what it does if measurement is wrong
            Me.txtMeasurement1.SetFocus
            checkmeasurements = False
        ElseIf Val(Me.txtMeasurement2) > Val(VariableName) Then
            MsgBox ("Measurement entered is too large")
            Me.txtMeasurement2.SetFocus
            checkmeasurements = False
        ElseIf Val(Me.txtMeasurement3) > Val(VariableName) Then
            MsgBox ("Measurement entered is too large")
            Me.txtMeasurement3.SetFocus
            checkmeasurements = False
        Else
            checkmeasurements = True
        End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #18
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Allow me to jump in -

    I don't think your checkmeasurements() function is quite right - it is only returning True for sure if ALL of the initial cutType and CutSize checks fail, and it checks no measurements at all, in other words if any if the lines that look like ElseIf Me.TxtCutType = "Hex" And Me.txtcutsize = "0.063" Then are true, then you cannot be sure what the function returns.
    The logic in it seems ok to me.

    It's an easy fix - just initialize the return value with Checkmeasurements = True before all the checks, and it will only return False if it encounters an error.

    You might also want to explicitly declare the type of the function: Private Function checkmeasurements() as boolean

    You can make your btnSaveandExit_Click much simpler :


    Private Sub btnSaveandExit_Click()
    If checkmeasurements Then
    Call saveandexitfcn End If
    End Sub


    The way you had it before it was calling checkmeasurements twice.

    HTH

    John
    Last edited by John_G; 03-27-2012 at 10:04 PM. Reason: Missing line breaks

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. need better VBA logic than I currently have
    By jscriptor09 in forum Programming
    Replies: 4
    Last Post: 11-27-2011, 09:16 AM
  2. Can't get the logic right.
    By Nouri31 in forum Queries
    Replies: 3
    Last Post: 03-31-2011, 08:25 AM
  3. Relationship Logic
    By Huddle in forum Access
    Replies: 2
    Last Post: 01-25-2011, 04:27 PM
  4. Nested If Statements Using Or (Logic Error)
    By IFA Stamford in forum Access
    Replies: 7
    Last Post: 12-30-2010, 08:53 AM
  5. Need help with code logic/consolidation
    By bg18461 in forum Programming
    Replies: 1
    Last Post: 03-31-2010, 04:19 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