A
aymarti
Hello All,
I'm a very beginner programmer and I am having problem with my form. I
'm trying to set up a form where the user decides how many elements will be
in the dynamic array using an input box during the form load event. (i.e, How
many name will you like to add? user enter 2 the form redims the array to two
elements) a form then opens and allows the user to enter names into a text
box.
These text boxes will populate the array and if the user enters more than the
number of names stated int the Input box, there is a msgbox stating the array
is full! Also if the user wants to see the name they have entered into the
array they can click a button on the form which will provide a msgbox with
the names they have entered.
Here is the code that I used for the Load Form
Private Sub Form_Load()
Dim dblNumberofNames As Double
Do While dblNumberofNames = 0
dblNumberofNames = Val(InputBox("How many names?", "Name Count"))
If dblNumberofNames = 0 Then
MsgBox "Please enter a number greater than 0.", vbCritical, "Correct Value
Required"
Else
ReDim sNameArrays1(dblNumberofNames)
End If
Loop
End Sub
This is the code for the Add Name event
Private Sub cmdAddName_Click()
Dim intCount As Integer
Dim intI As Integer
If IsNull(txtFname.Value) Or IsNull(txtLname.Value) Then
MsgBox "There Must be values for both First and Last names", vbCritical,
"Data Entry Error"
Exit Sub
If (UBound(sNameArray1) + 1) > dblNumberofNames Then
MsgBox "Sorry, the array is full!"
End If
Else
For intI = 1 To UBound(sNameArray1)
intCount = intCount + 1
Next
ReDim Preserve sNameArray1(intI)
txtFname.Value = " "
txtLname.Value = " "
End If
End Sub
Any suggestion why this doesn't work????
Thanks
I'm a very beginner programmer and I am having problem with my form. I
'm trying to set up a form where the user decides how many elements will be
in the dynamic array using an input box during the form load event. (i.e, How
many name will you like to add? user enter 2 the form redims the array to two
elements) a form then opens and allows the user to enter names into a text
box.
These text boxes will populate the array and if the user enters more than the
number of names stated int the Input box, there is a msgbox stating the array
is full! Also if the user wants to see the name they have entered into the
array they can click a button on the form which will provide a msgbox with
the names they have entered.
Here is the code that I used for the Load Form
Private Sub Form_Load()
Dim dblNumberofNames As Double
Do While dblNumberofNames = 0
dblNumberofNames = Val(InputBox("How many names?", "Name Count"))
If dblNumberofNames = 0 Then
MsgBox "Please enter a number greater than 0.", vbCritical, "Correct Value
Required"
Else
ReDim sNameArrays1(dblNumberofNames)
End If
Loop
End Sub
This is the code for the Add Name event
Private Sub cmdAddName_Click()
Dim intCount As Integer
Dim intI As Integer
If IsNull(txtFname.Value) Or IsNull(txtLname.Value) Then
MsgBox "There Must be values for both First and Last names", vbCritical,
"Data Entry Error"
Exit Sub
If (UBound(sNameArray1) + 1) > dblNumberofNames Then
MsgBox "Sorry, the array is full!"
End If
Else
For intI = 1 To UBound(sNameArray1)
intCount = intCount + 1
Next
ReDim Preserve sNameArray1(intI)
txtFname.Value = " "
txtLname.Value = " "
End If
End Sub
Any suggestion why this doesn't work????
Thanks