Prog

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Sub Using_InputBox_Method()

Dim Response As Integer

' Run the Input Box.


Response = Application.InputBox("Enter a number.", _
"Number Entry", , 250, 75, "", , 1)

' Check to see if Cancel was pressed.


If Response <> False Then

' If not, write the number to the first cell in the first sheet.
Worksheets(1).Range("a1").Value = Response

End If

End Sub

The Input Box Function

In the example below, a series of If statements is used to check the entry. The InputBox is inside
a While loop to allow it to be re-shown if an error occurs. If all the conditions are true, the
entered number is written to cell A1 on the first worksheet and the loop is ended.
Sub Using_InputBox_Function()
Dim Show_Box As Boolean
Dim Response As Variant

' Set the Show_Dialog variable to True.


Show_Box = True

' Begin While loop.


While Show_Box = True

' Show the input box.


Response = InputBox("Enter a number.", _
"Number Entry", , 250, 75)

' See if Cancel was pressed.


If Response = "" Then

' If Cancel was pressed,


' break out of the loop.
Show_Box = False
Else
' Test Entry to find out if it is numeric.
If IsNumeric(Response) = True Then
' Write the number to the first
' cell in the first sheet in the active
' workbook.
Worksheets(1).Range("a1").Value = Response
Show_Box = False
Else
' If the entry was wrong, show an error message.
MsgBox "Please Enter Numbers Only"
End If
End If
' End the While loop.
Wend
End Sub
Combo box
DIm RST As New ADODB.RecordSet
Dim sSQL As String

sSQL = "Select * From MyTable Where RollNo = " & Val(Combo1.Text)


RST.Open sSQL, Conn
If Not RSt.EOF Then
txtName.Text = RST("Name")
txtAdd.Text = RST("Addr")
txtAge.Text = RST("Age")
Else
txtName.Text = ""
txtAdd.Text = ""
txtAge.Text = ""
End If
RST.Close
Set RST=Nothing

You might also like