PDA

View Full Version : MsgBox and Input Box Macro



AZIQN
02-26-2009, 01:34 PM
Hi, I have two things I'd like to accomplish:

1. Yes/No MsgBox asking the user if they wish to proceed with formatting:
- yes - continue with code
- no - exit the code

2. A multiple field input box that requests the user to enter:
- Month
- Day
- Year
(all 3 in separate boxes, so that the stored values can be used differently in variable filenames and folders, etc.)

Thanks for your help!

Bob Phillips
02-26-2009, 01:42 PM
1. a simple


If MsgBox("question") = vbYes Then

... continue
End If


2 - use 3 inputboxes separately, or a custom user form

CreganTur
02-26-2009, 02:52 PM
Creating a custom UserForm is the best way to fulfill your #2 requirement. Using 3 inputboxes in a row will work... but it looks unprofessional. Plus, you cannot control what a user enters into an Input box.

If you use a UserForm, you can create validation code that checks what the user enters against what you define to be acceptable returned values, and reject anything that doesn't fit.

AZIQN
02-26-2009, 03:32 PM
Thanks for the info. Can you give me any example of a simple userform that might be similar to what I'm trying to do, to get me started? Also, what would the Call statement look like in the main Sub to reference the userform? Thanks in advance!

lucas
02-26-2009, 09:18 PM
I must be missing something. I don't understand why you need 3 textboxes to get the date to use to name files and folders......

Either way you should be able to figure out a few things from this.

Look in module1 for the code that is run from the sheet to open the userform.

lucas
02-26-2009, 09:30 PM
I'm bored this evening so here is a simpler version that shows how to just put the value entered in textbox1 into range A1...

You can use textbox1.value and assign it to a variable for other uses.

mikerickson
02-26-2009, 11:59 PM
Dim uiDate As Variant

Do
uiDate = Application.InputBox("Enter a date.", Default:=Format(Date, "mmm. d, yyyy"), Type:=2)
If uiDate = "False" Then Exit Sub: Rem cancel pressed
Loop Until IsDate(uiDate)

uiDate = CDate(uiDate)

MsgBox uiDate & " was entered."