PDA

View Full Version : Solved: User Form/ Database Problems



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

lucas
07-27-2006, 07:53 PM
Hi Steve,
It would really help if you could post a sanitized version of your workbook with any sensitive data removed. It would save responders from having to reproduce your userform, etc. Your problem sounds pretty easy if we could see it I'm sure we could "Git er done".....

Steve41031
07-27-2006, 08:01 PM
My workbook is fairly quite simple. The userform contains 8 text boxes: last name, first name, address, city, state, zip, phone and cell. it has three command buttons, enter, search and cancel. It has two sheets for data. I hope this helps you bellter understand it. Thanks

lucas
07-27-2006, 08:07 PM
Too much char this evening so here is an example along the lines you have mentioned.....should fill in some blanks for you.

lucas
07-27-2006, 08:11 PM
I just noticed your a new member of the forum...welcome to vbaexpress!

Steve41031
07-27-2006, 08:19 PM
Here is my workbook...........I think what you had worked great........I will try to apply it to mine.
Thank You very much !!!

lucas
07-27-2006, 08:35 PM
Glad to help Steve, if you have problems be sure to post back here and someone will point you in the right direction.

ps I worked a union job at Ashland a couple of years back....union electrician?