473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

method range of object globally failed error

Hi all

I created a database via VB and saved it in excel sheet

I have 10 command buttons and 10 text box controls on the vb form and i coded in the way to get the data from the user

once the user entered the data, i coded in vb to pass all the vaues to an excel sheet and to save it

when i executed the vb application, as i designed, it asks for the data from the user

when i enter the data and save it,ya it successfull

One thing i have to say here is,
if i want to enter next record, i have to stop running the application and i have to close all the user interaction windows..if so,i can add many records and i dont have any problem with that

i added more than 10 records and i found everything was going good and also i can see all the records which i saved in a singl excel sheet as i designed and coded in vb

but when i tried adding the next record by stop running the application but without closing the user interaction windows, i am getting error as "method range of object global failed"

and the following is the row where the error is shown
************************************************** **
NextToBlankRow = Sheets("Sheet1").Range(BlankRowCell).Offset(1, 0).Row
************************************************** ***
After getting this error,

Sometimes the excel file is opened with the propmpting msg "Do you want to save the changes"

I i give yes,it is opening with the save as dialog box with the file name "Copy of 'filename' ".

I need my data to be saved in the same file name not with othe name

Some other times, when i try to open the excel file rom the local drives, it is not at all opening

the following is the code where i made the excel to get the user's data from vb and to save it

************************************************** ***

Sub Appending(TBooksNames 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.Application
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.Application

Set oXLBook = oXLApp.Workbooks.Open("D:\Hema\DB.xls")
Set oXLSheet = oXLBook.Worksheets(1)
Set oXLRange = oXLSheet.UsedRange


oXLRange.SpecialCells(xlCellTypeLastCell).Activate
'BlankRow = ActiveSheet.Range("a65536").End(xlUp).Offset(1, 0).Row
BlankRowNum = oXLApp.ActiveCell.Row + 1
BlankRowCell = "A" & BlankRowNum
NextToBlankRow = Sheets("Sheet1").Range(BlankRowCell).Offset(1, 0).Row
TitleRowCell = "A" & NextToBlankRow
Sheets("Sheet1").Range(TitleRowCell) = "BOOKS RECORD"

oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TBksNames
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = BksNames

oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TNoOfBks
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = NoOfBks


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TSenName
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = SenName


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TRecName
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = RecName

oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TGen
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = Gen


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TStrNo
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = StrNo


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TCit
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = Cit


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TState
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = State


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TPstCd
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = PstCd


oXLRange.SpecialCells(xlCellTypeLastCell).Activate

newFstRow = oXLApp.ActiveCell.Row + 1

newFstCell = "A" & newFstRow
Sheets("Sheet1").Range(newFstCell) = TDtAndTime
newScndCell = "B" & newFstRow
Sheets("Sheet1").Range(newScndCell) = DtAndTime

oXLSheet.Columns("A:C").ColumnWidth = 20
oXLSheet.Rows("1:6").RowHeight = 20

With oXLSheet.Columns("A")
.Font.Bold = True
.Font.Italic = True
.Font.ColorIndex = 25
.Font.Size = 13
End With

With oXLSheet.Columns("B")
.Font.ColorIndex = 50
.Font.Size = 10
End With

With oXLSheet.Columns("A:B")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With

oXLApp.Visible = True

Set oXLSheet = Nothing

oXLBook.Close

'oXLApp.ActiveWorkbook.SaveAs ("D:\Hema\Database.xls")

oXLApp.Quit

Set oXLBook = Nothing
Set oXLApp = Nothing

End Sub

************************************************** **

i am new to vb so i am not sure where i am going wrong

please anyone help in this

all i need is,the users data to be saved even if other user interction windows are opened

please help me out

Thank you
Apr 22 '12 #1
3 1804
'... im not sure, but maybe..

Dim oXLApp as Excel.
Application
Set oXLApp = New Excel.Application

'you create another instance of *.xls when you open your *.xls database.

'thats why when you close your *.xls file the another instance asking you if you want to save the copy.
Apr 23 '12 #2
in access there is record count, wherein your *.xls database dont have this..

try to use a certain cell to hold the total rows occupied by data (RecordCount),

then if you want to add new record,

get the total row first,
then total row + 1 (for the row to movenext)
then put your record,
update the cell containing the row count,
then save.

*****
a cell that contains the row count..
(rs.RecordCount in access)

row count + 1
(rs.Movenext in access)
Apr 23 '12 #3
Thank you Rekedtechie

I will try it
Apr 24 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thomas | last post by:
Hi dudes, I have a range object for text (not the one in the IE, the one for Mozilla). Now I have a function to reduce/move the range in the text to the LEFT, e.g.:...
0
by: Bill Clark | last post by:
I just had MS Access 97 loaded on my machine. When I try to use the Chart Wizard, I get an error stating: Method 'Form' of object '_Subform' failed Any thoughts? Is there something that...
2
by: Todd | last post by:
This has really been my day for wierd problems sorting one of my forms (a subform actually)... so here's another one. I am now receiving the following error Run-time error '-2146500594...
0
by: Simon | last post by:
Hi I try to open a CR report file located on the network path from a web form developed with vs2003 and CR for Visual Studio, but the Load method of ReportDocument object always return error. ...
2
by: Lauren Wilson | last post by:
Hi folks, I have an Access 2003 app that works perfectly on my computer. However, when we install it on OTHER computers that ALSO have access 2003 we get an error on startup: Error:...
2
by: Reginald Bal | last post by:
Hello, I created a main form with 2 subforms. In an attempt to move to the next record (or new record) on the main form I get the error " Method 'requery' of object '_Subform' failed". The...
0
by: mse07 | last post by:
hi for every one i using program for send e-mail and i use 'IDHTMLEdit' to load text file with message but after i load file and run program ,compiler show following messagebox: ...
7
by: luke324 | last post by:
Hi everyone. Can anyone help me? I'm using VB6 on windows XP sp2, and I'm trying to build outputs of my program. It works just fine using the interpreter, but when I try to build outputs it gives...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
0
by: kaushalgajjar | last post by:
Hi, I had created an active-x control (ocx) in vb6 and i have used in VB.Net and HTML using ClassId reference and the active-x was working fine with ASP.Net, HTML and VB6. Now the active-x is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.