Results 1 to 15 of 15
  1. #1
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25

    if Then with Yes/No

    My Goal



    I want to make sure the user is aware they are entering the right qty to be booked out.

    I therefore want this sort of procedure to run on click of a button


    If the user enters a
    Remove Qty > Qty when they
    click add to cart

    I want a message to flag up warning
    them that they are trying to
    book out more than available with
    a YES / NO option to continue .

    If the user select Yes then do
    what it should if they click no to
    focus on the remove qty box


    I currently have this on the onclick button so have no idea where to enter the code now... any pointers would be really appreciated


    Code:
    Option Compare Database
    
    
    
    
    Private Sub AddToCart_Click()
     Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
    
      Set db = CurrentDb()
      
      strSQL = "SELECT * FROM tTempPartsIssued WHERE 1=0"
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
    
      rs.AddNew
      rs!PartNumber = Me.PartID
      rs!QTY = Me.RemoveQty
      rs.Update
    
    
      rs.Close
      Set rs = Nothing
      Set db = Nothing
     Forms!frmStocksearch.ListBoxcart.Requery
    
    
     Forms!frmStocksearch.Text93.Requery
     
        DoCmd.Close acForm, Me.Name
     
      
    End Sub
    Click image for larger version. 

Name:	If Then.jpg 
Views:	18 
Size:	95.3 KB 
ID:	45311

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Something like (aircode untested)

    Code:
    If MsgBox("Qty to remove is greater than available qty!" & vbcrlf & "Press Yes to continue or No to Cancel",VbInformation + VbYesNo, "Qty Check?") = VbNo Then 
        Me.txtRemove.Setfocus
        Exit Sub
    End if
    Replace txtRemove with your control name
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    So qty is bound and the 40 shown was not entered by the user and withdraw is also bound to a table? Then perhaps use the BeforeUpdate event of the withdraw control and present you message box if withdraw > qty. If user selects no, cancel the update, undo the entry and set focus back to the withdraw control.

    EDIT - I would not do this in the button click event as the user could move off of the record and the entered value would remain.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Why can they add more than available?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25
    there maybe a stock discrepancy....i have a plan to deal with a Yes response but need to get this right first

    Example...

    If there was 70 in the box... the system may say 61 but they physically counted the 70 to remove

    hope that makes sense

  6. #6
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25
    this works to a point thanks.... however i get the message every time i click the button regardless, if it's greater, level or below, i only need message if its actually more than the available qty...

    Quote Originally Posted by Minty View Post
    Something like (aircode untested)

    Code:
    If MsgBox("Qty to remove is greater than available qty!" & vbcrlf & "Press Yes to continue or No to Cancel",VbInformation + VbYesNo, "Qty Check?") = VbNo Then
        Me.txtRemove.Setfocus
        Exit Sub
    End if
    Replace txtRemove with your control name

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Well you have to enclose that code with the test for >, though if I counted 70, then I would add the correction to get 70?

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    You have no decision block - an outer IF block that makes the comparison between the controls?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25
    Not going to Lie.... I have no idea what you just said Sorry!

    I am trying hard to get my head around this, I know what's in my head but can't seem to translate it to get it to work.

    Quote Originally Posted by Micron View Post
    You have no decision block - an outer IF block that makes the comparison between the controls?

  10. #10
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25
    Correct, 100% in a normal world!!! however this a site where they don't want just anyone adjusting the qty's ... so i have to track the poor systems they have in place.



    Quote Originally Posted by Welshgasman View Post
    Well you have to enclose that code with the test for >, though if I counted 70, then I would add the correction to get 70?

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I said the same thing as Welshgasman only he said it simpler. Something like
    Code:
    If Me.Withdraw > Me.Qty Then
      If MsgBox("Qty to remove is greater than available qty!" & vbcrlf & "Press Yes to continue or No to Cancel",VbInformation + VbYesNo, "Qty Check?") = VbNo Then
        Me.Withdraw.Setfocus
        Exit Sub
      End If
    
    'whatever should happen if user chose Yes goes here?
    End if
    Again, I would not do this in the button click event, but what the hay?

    EDIT - Can't imagine you'll get a whole lot of records with this Select statement
    "SELECT * FROM tTempPartsIssued WHERE 1=0"
    Last edited by Micron; 05-25-2021 at 11:31 AM. Reason: code correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25
    now that does exactly what i need thanks... one final question.

    is there a way to delete the qty previously entered in this field when it sets focus?

    Me.Withdraw.Setfocus

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Me.Withdraw = 0
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    chimp8471 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    25
    Many thanks... sure i seem a spoon...

    Thanks all

    Quote Originally Posted by Welshgasman View Post
    Me.Withdraw = 0

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Or me.withdraw = Null
    Zero can be used (accidentally or not) by the user whereas Null not so much.
    I've never 100% understood the claims that nothing can ever equal null, yet we can create an expression like that and it works.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

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