Hi all
I am trying to create a database using vb6 and excel
I created few controls on the vb form and coded to get the details from the user
I code in the way to pass the data which i got from the user to an excel sheet
I named a function in a module as "Appending" and i made it to receive all the data through arguments
And almost I coded correctly to make the database look in the format i need
Eveeything is OK,but when I am running the program I am getting "Applicatio n defined or object defined error"..
This is the line where i am getting the error
*************** ***************
NextToBlankRow = ActiveSheet.Ran ge(BlankRowCell ).End(xlDown).O ffset(1, 0).Row
*************** *************** ****
As I am in the learning phase of VB6, I am not sure where I am going wrong
Please look at my code below and help me out in this
This is the module where i made the procedure to accept all the values from the vb form and to save it in an excel file in the format i need
MY CODE SNIPPET
*************** *************** *************** **********
Sub Appending(TBook sNames As String, BooksNames As Variant, TNoOfBooks As String, NoOfBooks As Integer, TSenderName As String, SenderName As Variant, TRecipientName As String, RecipientName As Variant, TGender As String, Gender As String, TStreetNo As String, StreetNo As Variant, TCity As String, City As String, TState As String, State As String, TPostCode As String, PostCode As Long, TDateAndTime As String, DateAndTime As Variant)
Dim oXLApp As Excel.Applicati on
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
Dim oXLRange As Excel.Range
Dim newFstRow As Integer
Dim newFstCell As Variant
Dim newScndCell As Variant
Dim BlankRow As Integer
Dim BlankRowNum As Integer
Dim BlankRowCell As Variant
Dim NextToBlankRow As Integer
Dim TitleRowCell As Variant
TBksNames = TBooksNames
BksNames = BooksNames
TNoOfBks = TNoOfBooks
NoOfBks = NoOfBooks
TSenName = TSenderName
SenName = SenderName
TRecName = TRecipientName
RecName = RecipientName
TGen = TGender
Gen = Gender
TStrNo = TStreetNo
StrNo = StreetNo
TCit = TCity
Cit = City
TSta = TState
Sta = State
TPstCd = TPostCode
PstCd = PostCode
TDtAndTime = TDateAndTime
DtAndTime = DateAndTime
Set oXLApp = New Excel.Applicati on
Set oXLBook = oXLApp.Workbook s.Open("D:\Hema \Database.xls")
Set oXLSheet = oXLBook.Workshe ets(1)
Set oXLRange = oXLSheet.UsedRa nge
'oXLRange.Speci alCells(xlCellT ypeLastCell).Ac tivate
BlankRow = ActiveSheet.Ran ge("a65536").En d(xlUp).Offset( 1, 0).Row
'BlankRowNum = oXLApp.ActiveCe ll.Row + 1
BlankRowCell = "A" & BlankRowNum
NextToBlankRow = ActiveSheet.Ran ge(BlankRowCell ).End(xlDown).O ffset(1, 0).Row
TitleRowCell = "A" & NextToBlankRow
ActiveSheet.Ran ge(TitleRowCell ) = "BOOKS RECORD"
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TBksNames
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = BksNames
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TNoOfBks
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = NoOfBks
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TSenName
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = SenName
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TRecName
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = RecName
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TGen
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = Gen
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TStrNo
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = StrNo
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TCit
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = Cit
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TState
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = State
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TPstCd
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = PstCd
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TDtAndTime
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = DtAndTime
oXLSheet.Column s("A:C").Column Width = 20
oXLSheet.Rows(" 1:6").RowHeigh t = 20
With oXLSheet.Column s("A")
.Font.Bold = True
.Font.Italic = True
.Font.ColorInde x = 25
.Font.Size = 13
End With
With oXLSheet.Column s("B")
.Font.ColorInde x = 50
.Font.Size = 10
End With
With oXLSheet.Column s("A:B")
.HorizontalAlig nment = xlCenter
.VerticalAlignm ent = xlCenter
End With
oXLApp.Visible = True
oXLBook.Close
oXLApp.Quit
Set oXLSheet = Nothing
Set oXLBook = Nothing
Set oXLApp = Nothing
End Sub
Please someone help me
I am trying to create a database using vb6 and excel
I created few controls on the vb form and coded to get the details from the user
I code in the way to pass the data which i got from the user to an excel sheet
I named a function in a module as "Appending" and i made it to receive all the data through arguments
And almost I coded correctly to make the database look in the format i need
Eveeything is OK,but when I am running the program I am getting "Applicatio n defined or object defined error"..
This is the line where i am getting the error
*************** ***************
NextToBlankRow = ActiveSheet.Ran ge(BlankRowCell ).End(xlDown).O ffset(1, 0).Row
*************** *************** ****
As I am in the learning phase of VB6, I am not sure where I am going wrong
Please look at my code below and help me out in this
This is the module where i made the procedure to accept all the values from the vb form and to save it in an excel file in the format i need
MY CODE SNIPPET
*************** *************** *************** **********
Sub Appending(TBook sNames As String, BooksNames As Variant, TNoOfBooks As String, NoOfBooks As Integer, TSenderName As String, SenderName As Variant, TRecipientName As String, RecipientName As Variant, TGender As String, Gender As String, TStreetNo As String, StreetNo As Variant, TCity As String, City As String, TState As String, State As String, TPostCode As String, PostCode As Long, TDateAndTime As String, DateAndTime As Variant)
Dim oXLApp As Excel.Applicati on
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
Dim oXLRange As Excel.Range
Dim newFstRow As Integer
Dim newFstCell As Variant
Dim newScndCell As Variant
Dim BlankRow As Integer
Dim BlankRowNum As Integer
Dim BlankRowCell As Variant
Dim NextToBlankRow As Integer
Dim TitleRowCell As Variant
TBksNames = TBooksNames
BksNames = BooksNames
TNoOfBks = TNoOfBooks
NoOfBks = NoOfBooks
TSenName = TSenderName
SenName = SenderName
TRecName = TRecipientName
RecName = RecipientName
TGen = TGender
Gen = Gender
TStrNo = TStreetNo
StrNo = StreetNo
TCit = TCity
Cit = City
TSta = TState
Sta = State
TPstCd = TPostCode
PstCd = PostCode
TDtAndTime = TDateAndTime
DtAndTime = DateAndTime
Set oXLApp = New Excel.Applicati on
Set oXLBook = oXLApp.Workbook s.Open("D:\Hema \Database.xls")
Set oXLSheet = oXLBook.Workshe ets(1)
Set oXLRange = oXLSheet.UsedRa nge
'oXLRange.Speci alCells(xlCellT ypeLastCell).Ac tivate
BlankRow = ActiveSheet.Ran ge("a65536").En d(xlUp).Offset( 1, 0).Row
'BlankRowNum = oXLApp.ActiveCe ll.Row + 1
BlankRowCell = "A" & BlankRowNum
NextToBlankRow = ActiveSheet.Ran ge(BlankRowCell ).End(xlDown).O ffset(1, 0).Row
TitleRowCell = "A" & NextToBlankRow
ActiveSheet.Ran ge(TitleRowCell ) = "BOOKS RECORD"
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TBksNames
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = BksNames
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TNoOfBks
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = NoOfBks
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TSenName
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = SenName
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TRecName
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = RecName
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TGen
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = Gen
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TStrNo
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = StrNo
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TCit
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = Cit
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TState
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = State
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TPstCd
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = PstCd
oXLRange.Specia lCells(xlCellTy peLastCell).Act ivate
newFstRow = oXLApp.ActiveCe ll.Row + 1
newFstCell = "A" & newFstRow
ActiveSheet.Ran ge(newFstCell) = TDtAndTime
newScndCell = "B" & newFstRow
ActiveSheet.Ran ge(newScndCell) = DtAndTime
oXLSheet.Column s("A:C").Column Width = 20
oXLSheet.Rows(" 1:6").RowHeigh t = 20
With oXLSheet.Column s("A")
.Font.Bold = True
.Font.Italic = True
.Font.ColorInde x = 25
.Font.Size = 13
End With
With oXLSheet.Column s("B")
.Font.ColorInde x = 50
.Font.Size = 10
End With
With oXLSheet.Column s("A:B")
.HorizontalAlig nment = xlCenter
.VerticalAlignm ent = xlCenter
End With
oXLApp.Visible = True
oXLBook.Close
oXLApp.Quit
Set oXLSheet = Nothing
Set oXLBook = Nothing
Set oXLApp = Nothing
End Sub
Please someone help me