vaughn9
Technical User
- Sep 23, 2001
- 183
I have created some text boxes to enter information. i want the information to go to excel when I click my command button. This is my code
'info placed in General
Dim oExcel As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim Surname, Firstname, Pa, DOB, Tel As String
Private Sub Command1_Click()
Set oBook = oExcel.Workbooks.Add()
Set oSheet = oExcel.ActiveSheet
Rem makes Excel visible
oExcel.Visible = True
'specify value of textboxes
Surname = Text1
Firstname = Text2
Pa = parish
DOB = Text3
Tel = Text4
Rem fill in row values
oSheet.Cells(1, 1).Value = "SURNAME"
oSheet.Cells(1, 2).Value = "FIRSTNAME"
oSheet.Cells(1, 3).Value = "PARISH"
oSheet.Cells(1, 4).Value = "DOB"
oSheet.Cells(1, 5).Value = "Tel. No"
oSheet.Cells(2, 1).Value = Surname
oSheet.Cells(2, 2).Value = Firstname
oSheet.Cells(2, 3).Value = Pa
oSheet.Cells(2, 4).Value = DOB
oSheet.Cells(2, 5).Value = Tel
End Sub
My problem is that when I add a second record the first overwrites the second. I need to go to the next availble empty cell when I enter the second record so that the second persons information would begin in row3 column1, and the next in row4, column1. I was thinking if I say move down 1 and move across to the first cell on the left that might work but I am not too sure. I need my next record to go to the next available row.
Help
'info placed in General
Dim oExcel As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim Surname, Firstname, Pa, DOB, Tel As String
Private Sub Command1_Click()
Set oBook = oExcel.Workbooks.Add()
Set oSheet = oExcel.ActiveSheet
Rem makes Excel visible
oExcel.Visible = True
'specify value of textboxes
Surname = Text1
Firstname = Text2
Pa = parish
DOB = Text3
Tel = Text4
Rem fill in row values
oSheet.Cells(1, 1).Value = "SURNAME"
oSheet.Cells(1, 2).Value = "FIRSTNAME"
oSheet.Cells(1, 3).Value = "PARISH"
oSheet.Cells(1, 4).Value = "DOB"
oSheet.Cells(1, 5).Value = "Tel. No"
oSheet.Cells(2, 1).Value = Surname
oSheet.Cells(2, 2).Value = Firstname
oSheet.Cells(2, 3).Value = Pa
oSheet.Cells(2, 4).Value = DOB
oSheet.Cells(2, 5).Value = Tel
End Sub
My problem is that when I add a second record the first overwrites the second. I need to go to the next availble empty cell when I enter the second record so that the second persons information would begin in row3 column1, and the next in row4, column1. I was thinking if I say move down 1 and move across to the first cell on the left that might work but I am not too sure. I need my next record to go to the next available row.
Help