Error Adding to Spreadsheet Please help!!! Complex ?

G

gwoodby

Using the "add" button to add information to a specified area, It
does Not add to the combobox
I am Still very new to vba and Not really sure what im doing wrong, i
want it to test if the textboxes are empty, if they arent they
should test to see if it already exists, if it does tell me it does
and not allow me to create it, if it doesnt it should create it, and
add the information to the sheet.

Private Sub CmdAdd_Click()
Dim strNewPerson As String
Dim NewName As String
Dim cnt As Long
Dim NewParent As String
NewName = TxtFirstName.text & "," & TxtLastName.text
If Len(CBOMoFa) = 0 Or Len(TxtFirstName) = 0 Or Len(TxtLastName) = 0 _
Or Len(TxtChild) = 0 Then
MsgBox " Please Insert Missing Information ",
vbOKOnly ' If they are empty dont allow them to do it

End If
For cnt = 0 To CBONames.ListCount - 1
If NewName = CBONames.List(cnt) Then
MsgBox " This Person Is Already on the List", vbOKOnly
If CBONames.ListCount = 0 Then ' Hoping i
used this correctly

' basically if there are no names left then

' this is the new string add it to the form
strNewPerson = TxtFirstName & "," & TxtLastName & "," &
CBOMoFa & "," & _
TxtChild & "," & TxtIssued & "," & TxtServed
NewParent = GetArea(strNewPerson)
End If
cnt = cnt + 1
End If
Next
End Sub


This Function Should Find where the information shoudl be put

Private Function GetArea(strname As String)
Dim StrNewfound As String
Dim I As Integer
Dim cnt As Integer
I = 0
ParentArray = Array("Mother:1", "Mother:2", "Mother:3", "Putative
Father", "Putative Father:2", "Putative Father:3", "Putative Father:
4", _
"Putative Father:5", "Putative Father:6", "Father:1", "Father:2",
"Father:3", "Father:4", "Father:5", "Father:6", "Father:7", "Father:
8")

Do
For cnt = 25 To 41
StrNewfound = SplitMe(strname, 2) ' split the
string
If StrNewfound <> "" Then
If StrNewfound = ParentArray(I) Then ' test
to see if cbomofa and strnewfound are equal

Range("A5:AX4500").Find(TxtCaseName,
LookIn:=xlValues).Offset(0, cnt) = strname
CBONames.AddItem StrNewfound
GetArea = SplitMe(strname, 0)
End If
Else
MsgBox ParentArray(I) & " Already Exists"
End If
I = I + 1
cnt = cnt + 1
While ParentArray(I) <= 17

End Function


This is what im using to split the strings

Private Function SplitMe(strToSplit As String, intChoose As Integer)
As String
Dim vntX As Variant

vntX = Split(strToSplit, ",")

If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' vntX(0) is
TxtFirstName
ElseIf intChoose = 2 Then ' vntX(1) is TxtLastName
SplitMe = vntX(2) ' vntX(2) is
cbomofa combobox mother father
ElseIf intChoose = 1 Then ' vntX(3) is Childs name
TxtFirstName = vntX(0) ' vntX(4) is date
issued
TxtLastName = vntX(1) ' vntX(5) is date served
TxtChild = vntX(3)
If UBound(vntX) = 4 Then
TxtIssued = vntX(4)
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5)
Else
TxtServed = ""
End If
SplitMe = vntX(2)
End If
End Function
 
G

gwoodby

Using the "add" button to add information to a specified area, It
does Not add to the combobox
I am Still very new to vba and Not really sure what im doing wrong, i
want it to test if the textboxes are empty, if they arent they
should test to see if it already exists, if it does tell me it does
and not allow me to create it, if it doesnt it should create it, and
add the information to the sheet.

Private Sub CmdAdd_Click()
Dim strNewPerson As String
Dim NewName As String
Dim cnt As Long
Dim NewParent As String
NewName = TxtFirstName.text & "," & TxtLastName.text
If Len(CBOMoFa) = 0 Or Len(TxtFirstName) = 0 Or Len(TxtLastName) = 0 _
Or Len(TxtChild) = 0 Then
MsgBox " Please Insert Missing Information ",
vbOKOnly ' If they are empty dont allow them to do it

End If
For cnt = 0 To CBONames.ListCount - 1
If NewName = CBONames.List(cnt) Then
MsgBox " This Person Is Already on the List", vbOKOnly
If CBONames.ListCount = 0 Then ' Hoping i
used this correctly

' basically if there are no names left then

' this is the new string add it to the form
strNewPerson = TxtFirstName & "," & TxtLastName & "," &
CBOMoFa & "," & _
TxtChild & "," & TxtIssued & "," & TxtServed
NewParent = GetArea(strNewPerson)
End If
cnt = cnt + 1
End If
Next
End Sub

This Function Should Find where the information shoudl be put

Private Function GetArea(strname As String)
Dim StrNewfound As String
Dim I As Integer
Dim cnt As Integer
I = 0
ParentArray = Array("Mother:1", "Mother:2", "Mother:3", "Putative
Father", "Putative Father:2", "Putative Father:3", "Putative Father:
4", _
"Putative Father:5", "Putative Father:6", "Father:1", "Father:2",
"Father:3", "Father:4", "Father:5", "Father:6", "Father:7", "Father:
8")

Do
For cnt = 25 To 41
StrNewfound = SplitMe(strname, 2) ' split the
string
If StrNewfound <> "" Then
If StrNewfound = ParentArray(I) Then ' test
to see if cbomofa and strnewfound are equal

Range("A5:AX4500").Find(TxtCaseName,
LookIn:=xlValues).Offset(0, cnt) = strname
CBONames.AddItem StrNewfound
GetArea = SplitMe(strname, 0)
End If
Else
MsgBox ParentArray(I) & " Already Exists"
End If
I = I + 1
cnt = cnt + 1
While ParentArray(I) <= 17

End Function

This is what im using to split the strings

Private Function SplitMe(strToSplit As String, intChoose As Integer)
As String
Dim vntX As Variant

vntX = Split(strToSplit, ",")

If intChoose = 0 Then
SplitMe = vntX(0) & "," & vntX(1) ' vntX(0) is
TxtFirstName
ElseIf intChoose = 2 Then ' vntX(1) is TxtLastName
SplitMe = vntX(2) ' vntX(2) is
cbomofa combobox mother father
ElseIf intChoose = 1 Then ' vntX(3) is Childs name
TxtFirstName = vntX(0) ' vntX(4) is date
issued
TxtLastName = vntX(1) ' vntX(5) is date served
TxtChild = vntX(3)
If UBound(vntX) = 4 Then
TxtIssued = vntX(4)
Else
TxtIssued = ""
End If
If UBound(vntX) = 5 Then
TxtServed = vntX(5)
Else
TxtServed = ""
End If
SplitMe = vntX(2)
End If
End Function

PLEASE HELP!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top