PDA

View Full Version : Input Box Help



dub
06-13-2011, 09:01 AM
Hi,
I need code for an input box that uses a variable name in the prompt.
I would like it to look like this...
Title: Please provide initials
Msg: The system does not have initials for the user name "user name variable here". Please provide your initials for the purpose of tracking edits. Thank you.

Would like "ok" and "cancel" button. If cancel is pressed would like the following msg: You must provide you initials to continue.
This msg I would like "ok" button and "close program" button and if the close program button is pushed I would like the current workbook to close.

I already have code to get the user name and to make this get initials sub run upon opening the workbook.
Thanks a bunch!!:help
</IMG>

dub
06-13-2011, 01:01 PM
I have been working on the fore mentioned but I'm having some problems.
Here is the code I have so far
Private Sub Workbook_Open()
Initials
End Sub
Sub Initials()
Dim iRow As Integer, Initials As String, UserName As String, myForm As UserForm, vbCancel As String
UserName = Environ("USERNAME")

If WorksheetFunction.CountIf(Columns("A"), UserName) >= 1 Then
Else
Retry:
Initials = InputBox("The system does not have initials " & _
"for the user name " & UserName & "." & " Please provide your " & _
"initials for the purpose of tracking edits. Thank you.", "Please provide initials")
If Initials = vbCancel Then
Set myForm = New myForm
Load myForm
myForm.Show


End If
Cells(iRow + 1, 1).Select
ActiveCell.Value = UserName
ActiveCell.Offset(rowoffset:=0, columnoffset:=1).Value = Initials
End If

ExitProgram:
End Sub


I am getting an error for "ire.Show" that says object or property not supported.

My other problem is I can't figure out how to use the code for the buttons to go to a specific line in the main workbook code, shown about. I have two buttons: Retry and Exit Program. when exit program is pushed I want to go to a line in the main code that will close the current workbook; if Retry is pushed I want to go to the line Retry: in the above code.
Any help is appreciated Thanks!

mancubus
06-13-2011, 11:07 PM
you may play around with this:


Sub InputBoxExample()
'http://www.mrexcel.com/forum/showthread.php?t=35206
Dim Initials As Variant, UserName As String

UserName = Environ("USERNAME")

showInputBox:
Initials = Application.InputBox("System does not have initials for the user name " _
& UserName & ". Please provide your initials for the purpose of tracking edits." _
& " Thank you.", "Please provide Initials")
If Initials = False Then
MsgBox "You must provide your Initials to continue.", 48 + 1, vbOKCancel, "Cancel was clicked."
Exit Sub
ElseIf Initials = "" Then
MsgBox "You must click Cancel to exit.", 48, "You clicked Ok but entered nothing."
GoTo showInputBox
Else
MsgBox "You entered " & Initials & ".", 64, "Please click OK to resume."
End If
End Sub

mancubus
06-13-2011, 11:35 PM
ps:
48 +1 (or 49) = vbExclamation + vbOKCancel