Results 1 to 15 of 15
  1. #1
    Join Date
    Apr 2003
    Posts
    280

    Unanswered: Messagebox with textbox inside

    Is there a way to create a messagebox via VBA that display a statement to the user to enter in a data in a textbox that is located on the messagebox?

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Use InputBox instead of Messagebox
    Inspiration Through Fermentation

  3. #3
    Join Date
    Apr 2003
    Posts
    280
    Thanks! It works so far but I need for the inputbox to only display the "OK" button and validate it when it is click. How wouuld I going about doing that? I was hoping it would be similar to the messagebox, but no luck with it.

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Try something like this:

    Dim varReply as Variant
    varReply = Inputbox("Enter some text","User Input")
    'test to see if the user pressed cancel instead of OK
    If varReply = vbcancel then
    'perform some action
    Else
    If varReply = "" then

    'move on with what you need to do
    End If
    Inspiration Through Fermentation

  5. #5
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I posted the last one before I was done.... oops

    Try something like this:

    Dim varReply as Variant
    varReply = Inputbox("Enter some text","User Input")
    'test to see if the user pressed cancel instead of OK
    If varReply = vbcancel then
    'the user clicked cancel
    'perform some action
    Else
    If varReply = "" or isnull(varreply) then
    'the user hit OK, but didn't enter a value
    end if
    'the user entered info, and clicked ok
    'move on with what you need to do
    End If
    Inspiration Through Fermentation

  6. #6
    Join Date
    Apr 2003
    Posts
    280
    In your code, I don't see how it would able to retrieve the string from the Inputbox and the value when the user click 'OK' or 'Cancel', to be able to send to the same variable.

  7. #7
    Join Date
    Apr 2003
    Posts
    280
    To the Top!

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    if you don't trust rng's proposal, make a form with a textbox and OK button. takes more time & effort but you get to control all aspects of what the user plays with.

    izy

  9. #9
    Join Date
    Apr 2003
    Posts
    280
    Originally posted by izyrider
    if you don't trust rng's proposal, make a form with a textbox and OK button. takes more time & effort but you get to control all aspects of what the user plays with.

    izy
    What do you mean by don't trust his proposal? I trust or incorporate everyone comments to my problem that i post up on this forum. Before I make a comment on someone else code, I would test it out first then if it doesn't work the way I ask for people to help me out then I would post up my comments about it. Sorry, if I sound like I'm being mean to you but i'm not.

    Anyways, I don't want to do just a textbox on the form. I want it to be more direct to the user showing that there is a problem. The textbox on the form works but I want to learn the other method(inputbox).

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i was suprised at rng's proposed capture of the Cancel button... i tried it in A2K and it didn't work for me.

    vbCancel = 2 ...how would A determine if the user replied "2" or Cancelled?

    inputbox otherwise works exactly as rng describes, with (for me at least) cancel returning null.

    you don't have the button options with inputbox like you do with msgbox: just the one flavour with OK/Cancel buttons.

    izy

  11. #11
    Join Date
    Apr 2003
    Posts
    280
    Originally posted by izyrider
    i was suprised at rng's proposed capture of the Cancel button... i tried it in A2K and it didn't work for me.

    vbCancel = 2 ...how would A determine if the user replied "2" or Cancelled?

    inputbox otherwise works exactly as rng describes, with (for me at least) cancel returning null.

    you don't have the button options with inputbox like you do with msgbox: just the one flavour with OK/Cancel buttons.

    izy
    How did you got the cancel button to return a null?

  12. #12
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    yes sir!
    you are completely right: cancel returns a zero length string




    izy

  13. #13
    Join Date
    Apr 2003
    Posts
    280
    Originally posted by izyrider
    yes sir!
    you are completely right: cancel returns a zero length string




    izy
    HUH? I'm I missing something here. I don't understand your sarcastic remarks(literally).

    Anyways, I have got it to work but in a different way, rather then tryin get the values for the 'Ok' and 'Cancel' buttons, I just validate the text that the user enter in, if there was no data enter in, I would validate the null variable and do a "Do..Loop" until the user enter it in and correctly.

  14. #14
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    then we are both missing something!

    there was zero sarcasm intended - my earlier message stated that selecting Cancel in an input box returns Null... this is incorrect: it in fact returns an empty string "" which is absolutely not the same as a Null.

    Private Sub Test()
    if isnull(inputbox("enter something"))
    msgbox "was null" 'THIS NEVER HAPPENS, EVEN AFTER CANCEL
    else
    msgbox "was not null"
    endif
    end sub

    izy

  15. #15
    Join Date
    May 2002
    Location
    London
    Posts
    87
    A related and probably relevant question is how to create a custom Text Input box.

    I was looking at creating a popup to edit a (memo) comments field. which would pop up intitally as read only view notes shoing Close and Edit buttons and after hitting Edit would then have Clear, Save and Cancel options.

    Now all that is done but I couldn't see a way of returning the result other than using a global return variable. (The sturcture was a public function that called the notes form and reutrned the edited value).

    Has anyone got a neater structure?
    Code:
    Public Function EditNotes(strNotes As String) As String
    varReturn = strNotes
    DoCmd.OpenForm "frmEditNotes", acNormal 'Modal form sets varReturn on close 
    EditNotes = varReturn
    End Function

Posting Permissions

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