Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Jun 2005
    Posts
    102

    Unanswered: When cancel is clicked, nothing happens

    Take a look at the code below

    Code:
        
    
    'InputBox properties
        Dim Message, Title2, Default, MyValue
        Message = "Type 1 for handheld 1, type 2 for handheld 2, and so on (use 1 digit at all times). Note: You must type 'Done' when finished"   ' Set prompt.
        Title2 = "Which Handheld?"   ' Set title.
        Default = "0"   ' Set default.
        
        'MsgBox properties
        Dim Msg, Msg2, Style, Style2, Title, Title3, Response, MyString
        Msg = "Do you want to upload data from handheld(s)?"   ' Define message.
        Msg2 = "You must type 'Done' to cancel or exit this process"
        Style = vbYesNo + vbQuestion + vbDefaultButton2   ' Define buttons.
        Style2 = vbOKOnly
        Title = "Upload Data?"   ' Define title.
        Title3 = "Cancel Import"
        
        If Format(Now, "short time") >= "13:50" And Format(Now, "short time") < "14:00" Then
        MsgBox "It is almost 2:00 pm, you can not add anymore items", vbCritical, "LUM - PAR System"
        DoCmd.Close acForm, "frmTodaysOrder1"
        DoCmd.OpenForm "Switchboard", acNormal, "", "", acReadOnly, acIcon
        Else
        If Format(Now, "short time") >= "14:00" And Format(Now, "short time") < "18:00" Then
        MsgBox "You cannot modify an order after 2:00 pm, you must create a new order and issue a new PO.", vbInformation, "LUM - PAR System"
        DoCmd.Close acForm, "frmTodaysOrder1"
        DoCmd.OpenForm "Switchboard", acNormal, "", "", acReadOnly, acIcon
        Else
        Response = MsgBox(Msg, Style, Title)
        If Response = vbYes Then    ' User chose Yes.
        Do Until MyValue = "Done"
        MyValue = InputBox(Message, Title2, Default) ' Perform some action.
        
        Select Case MyValue
        Case 1
        SendKeys "y", False
        DoCmd.TransferText acImportDelim, "Tracer Import Specification", "tblImportTracer", "C:\Program Files\PALM\PDA1\Tracer\tracer.txt", False, ""
        Beep
        MsgBox "You have successfully imported data from handheld device 1.", vbInformation, "Import Successful"
        Case 2
        SendKeys "y", False
        DoCmd.TransferText acImportDelim, "Tracer Import Specification", "tblImportTracer", "C:\Program Files\PALM\PDA2\Tracer\tracer.txt", False, ""
        Beep
        MsgBox "You have successfully imported data from handheld device 2.", vbInformation, "Import Successful"
        End Select
        
        Loop
        
        End If
        End If
        End If
    Notice this code:
    If Response = vbYes Then ' User chose Yes.
    Do Until MyValue = "Done"
    MyValue = InputBox(Message, Title2, Default) ' Perform some action.

    It tells the user to type done and press OK (OK/Cancel is native window) if they are finished importing the data. When the user press cancel, nothing happens it still keeps on looping, what is wrong with it? Help please!
    The only true wisdom is in knowing you know nothing.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Nothing is wrong with it. It's doing exactly what you've told it: to loop until the user types in "done", which they haven't done if they click on cancel.
    Paul

  3. #3
    Join Date
    Jun 2005
    Posts
    102
    Quote Originally Posted by pbaldy
    Nothing is wrong with it. It's doing exactly what you've told it: to loop until the user types in "done", which they haven't done if they click on cancel.
    I'm sorry, i must have worded the question incorrectly. What I want the input box to do is, once the Cancel button is clicked, I want to just cancel the sub, (much like what happens when the user type done).
    The only true wisdom is in knowing you know nothing.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    The input box will return a ZLS ("") if the user clicks cancel, so you can test for that. Of course, if they clear your default and click on okay on an empty input box, that will also return a ZLS.
    Paul

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Usual solution to this problem is to create a custom message box form. Create public properties for the form. Open it modal (so all other code execution pauses). When a user clicks a button, set the property(ies) to the relevent value(s) and have the form make itself invisible. The paused code will now run - you can read the property and close the form.

    I have one knocking around somewhere if this seems a bit confusing.

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Jun 2005
    Posts
    102
    Quote Originally Posted by pootle flump
    Usual solution to this problem is to create a custom message box form. Create public properties for the form. Open it modal (so all other code execution pauses). When a user clicks a button, set the property(ies) to the relevent value(s) and have the form make itself invisible. The paused code will now run - you can read the property and close the form.

    I have one knocking around somewhere if this seems a bit confusing.

    HTH
    Pootle, may i please see an example?
    The only true wisdom is in knowing you know nothing.

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by rodrunner79
    Pootle, may i please see an example?
    Why of course you may.

    Of course, you could implement a lot more - data validation, bespoke buttons (instead of just the usual Yes, No, Cancel etc). Bare bones attached. I stripped down a prod db to produce this - I don't think I took anything out I shouldn't...

    If you know how to step through code (and if not google VB debugging, break points, stepping through code - best hours reading on VB you will ever spend) follow the execution process - the critical thing is the affect opening the form acDialog has.

    HTH
    Attached Files Attached Files
    Testimonial:
    pootle flump
    ur codings are working excelent.

  8. #8
    Join Date
    Mar 2005
    Posts
    261
    Quote Originally Posted by pbaldy
    The input box will return a ZLS ("") if the user clicks cancel, so you can test for that. Of course, if they clear your default and click on okay on an empty input box, that will also return a ZLS.
    Not quite correct.

    If you press Cancel, it will return a null-pointer.
    If you press Ok with no text it will return a zero length string (ZLS)

    So the following can be used:

    Code:
    Dim strTest As String
        
        strTest = InputBox("Leave blank or press cancel:")
        
        If StrPtr(strTest) = 0 Then
        
            'User Cancelled...
            MsgBox "You pressed cancel!"
            
        ElseIf Len(strTest) = 0 Then
            
            MsgBox "You entered nothing, but pressed OK"
            
        Else
        
            MsgBox "You entered: " & strTest
        
        End If
    Wayne Phillips
    http://www.everythingaccess.com

  9. #9
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Quote Originally Posted by waynephillips
    Not quite correct.

    If you press Cancel, it will return a null-pointer.
    If you press Ok with no text it will return a zero length string (ZLS)
    I'm not clear on what you mean, since I will get the message box if I click on Cancel:

    Code:
      If InputBox("whatever") = "" Then
        MsgBox "ZLS"
      End If
    Paul

  10. #10
    Join Date
    Mar 2005
    Posts
    261
    Quote Originally Posted by pbaldy
    I'm not clear on what you mean, since I will get the message box if I click on Cancel:

    Code:
      If InputBox("whatever") = "" Then
        MsgBox "ZLS"
      End If
    What I'm trying to point out is that there is a difference between pressing the Cancel button and entering a zero length string.

    In your example, because you are only thinking in terms of "VB Strings", you cannot determine whether the user pressed Cancel or whether they entered a zero string and pressed OK. In most cases this isn't an issue, but I was just correcting your terminology and providing an example of checking for a null-pointer string versus a zero-length string.

  11. #11
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I suppose I should have gone straight to Help , which states:

    If the user clicks Cancel, the function returns a zero-length string ("").
    Paul

  12. #12
    Join Date
    Mar 2005
    Posts
    261
    Quote Originally Posted by pbaldy
    I suppose I should have gone straight to Help , which states:

    If the user clicks Cancel, the function returns a zero-length string ("").
    Then I'm afraid Help is wrong !! Trust me...

  13. #13
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Looks like we posted at the same time. I'm certainly interested to find out a way to tell the difference. What is the function StrPtr?
    Paul

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Coo -

    Code:
    ?strptr("")
     181041716 
    ?strptr(vbNullString)
     0
    Testimonial:
    pootle flump
    ur codings are working excelent.

  15. #15
    Join Date
    Mar 2005
    Posts
    261
    Quote Originally Posted by pbaldy
    Looks like we posted at the same time. I'm certainly interested to find out a way to tell the difference. What is the function StrPtr?
    StrPtr is an undocumented (and hidden) function that returns the Long pointer which a string is defined by.
    (Remember that a String is actually a Long pointer which "points" to the textual data in memory)

    A VB/VBA String can be a Null-String (the pointer is Zero) or a real String (the pointer does point to textual data in memory). To complicate this, all VB functions will treat a Null-String as a Zero Length String, even though technically it is not!

    So we can use StrPtr to determine if the VB String is a real Zero Length String or whether it is really a NULL pointer.

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •