You can build a much better reuseable input box on your own with out the API workaround. Provides a whole lot more flexibility. I would never use an input box in an access application for any reason. You are very limited in what you can do, and to add data verification you need another work around. Here is a better way that is more flexible and easier.
build a Input box form.
Need
text box for the input
text box for the message
Command button OK
Command button Cancel
Format it to fit your needs
code on form:
Code:
Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdOK_Click()
Me.Visible = False
End Sub
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.lblMessage.Caption = Split(Me.OpenArgs, ";")(0)
Me.Caption = Split(Me.OpenArgs, ";")(1)
Me.txtBxInput = Split(Me.OpenArgs, ";")(2)
Else
MsgBox "Need to open from function myInputBox"
End If
End Sub
Build a function in a standar module
Code:
Public Function myInputBox(prompt As String, Optional Title As String = "", Optional Default As Variant = "") As Variant
Dim strArgs As String
Dim frm As Access.Form
strArgs = prompt & ";" & Title & ";" & Default
DoCmd.OpenForm "frmInputBox", , , , , acDialog, strArgs
If CurrentProject.AllForms("frmInputBox").IsLoaded Then
Set frm = Forms("frmInputBox")
myInputBox = frm.txtBxInput
DoCmd.Close acForm, frm.Name
End If
End Function
now to use it. In this example returning the value back to a textbox on another form and setting the input box default value to the value in the textbox
The caption on the Input box will be "Student ID" the message will be "Enter Student ID" and the default will be the value in the calling forms txtbxone.
Code:
Private Sub cmdMyInput_Click()
Me.txtBxOne = myInputBox("Enter StudentID", "Student ID", Me.txtBxOne)
End Sub
I did not set this up to allow you to pass a format for the textbox. So if you want to use this for other things then make a new function and new input box form.
Call the form
frmPasswordInputBox
then call the function myPasswordInputBox
Have that function call frmPasswordInputBox instead of frmInputBox
That would be a little easier then having to pass a format string in to the input box. Although this could be done.
The way this works is that the function calls the input box form in dialog mode. Code execution halts in the calling code until either the input form is hidden (OK) or close (Cancel). Code execution then returns to the myInputBox function. If the form is hidden, then it reads the value and closes the inputbox. Then returns the value to the original code that called the function.
This concept is by far the best way in general to return values from dialog forms.
The only limitation on this is the size of the inputbox and size of the message. I made my form big enough to handle a large message. It is a transparent textbox so you can not really tell. However, If I wanted I could simply write some code to size the message textbox and the form to match.