Steve41031
07-27-2006, 07:16 PM
Hi. I have just started learning VBA and am fascinated with it, but I have found very little information that can help me understand it better. Currently I am working on a spreadsheet and have a an issue with how to program it. The userform works but when I enter the information into the base it will not allow me to add a new row of data. It only deletes what i had and stores what is in the user form in the same row. Is there a simple solution to this? I have a reference book and tried using the code like it stated but it keeps giving me a sytax error. Any help will be very much appreciated.
Thanks
Here is the way my code looks, I am new to this so any help would be great.I dont really understand about variable or intergers yet but I am learning
Private Sub tbenter1_Click()
Dim x As Range
Dim j As XlRowCol
Dim inextrow As Integer
Set x = Sheet2.Rows(3)
j = xlRows
With x
.Cells(j, 1) = uf1.tblname1.Value
End With
If uf1.tblname1.TextLength = 0 Then
MsgBox "Please Enter a Last Name", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 2) = uf1.tbfname1.Value
End With
If uf1.tbfname1.TextLength = 0 Then
MsgBox "Please Enter a First Name", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 3) = uf1.tbadd1.Value
End With
If uf1.tbadd1.TextLength = 0 Then
MsgBox "Please Enter an Address", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 4) = uf1.tbcity1.Value
End With
If uf1.tbcity1.TextLength = 0 Then
MsgBox "Please Enter a City", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 5) = uf1.tbstate1.Value
End With
If uf1.tbstate1.TextLength = 0 Then
MsgBox "Please Enter a State", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 6) = uf1.tbzip1.Value
End With
If uf1.tbzip1.TextLength = 0 Then
MsgBox "Please Enter a Zip Code", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 7) = uf1.tbhome1.Value
End With
If uf1.tbhome1.TextLength = 0 Then
MsgBox "Please Enter a Telephone Number", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 8) = uf1.tbcell1.Value
End With
Unload uf1
Workbooks.Application.GetSaveAsFilename
End Sub
Steve, please select your code and hit the vba button when posting. I have edited your code in this way, it makes it easier to read. Lucas
Thanks
Here is the way my code looks, I am new to this so any help would be great.I dont really understand about variable or intergers yet but I am learning
Private Sub tbenter1_Click()
Dim x As Range
Dim j As XlRowCol
Dim inextrow As Integer
Set x = Sheet2.Rows(3)
j = xlRows
With x
.Cells(j, 1) = uf1.tblname1.Value
End With
If uf1.tblname1.TextLength = 0 Then
MsgBox "Please Enter a Last Name", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 2) = uf1.tbfname1.Value
End With
If uf1.tbfname1.TextLength = 0 Then
MsgBox "Please Enter a First Name", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 3) = uf1.tbadd1.Value
End With
If uf1.tbadd1.TextLength = 0 Then
MsgBox "Please Enter an Address", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 4) = uf1.tbcity1.Value
End With
If uf1.tbcity1.TextLength = 0 Then
MsgBox "Please Enter a City", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 5) = uf1.tbstate1.Value
End With
If uf1.tbstate1.TextLength = 0 Then
MsgBox "Please Enter a State", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 6) = uf1.tbzip1.Value
End With
If uf1.tbzip1.TextLength = 0 Then
MsgBox "Please Enter a Zip Code", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 7) = uf1.tbhome1.Value
End With
If uf1.tbhome1.TextLength = 0 Then
MsgBox "Please Enter a Telephone Number", _
vbExclamation, "Warning !!"
Exit Sub
End If
With x
.Cells(j, 8) = uf1.tbcell1.Value
End With
Unload uf1
Workbooks.Application.GetSaveAsFilename
End Sub
Steve, please select your code and hit the vba button when posting. I have edited your code in this way, it makes it easier to read. Lucas