Dear all,
I wrote the VB code in a "button press event" as below in
which is retrieve data from SQL server and insert the data
into Excel. After that, I would call Excel "subtotal" API
to build a subtotal figures. For first time, it is working
fine. But in the second time, I try to execute the event
again. Whenever it runs the command "Selection.Subtotal
GroupBy:=2, Function:=xlSum, TotalList:=Array(3)", it
always raises the error "Err 91 : Object variable or With
block variable not set". Please advise.
Thanks & Regards
Public Function getPlatinum()
On Error GoTo ErrorHandler
Dim rstAP As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQL1 As String
Dim rowNo As Integer
Dim oXLApp As Excel.Application
Dim oXLWBook As Excel.Workbook
Dim oXLWSheet As Excel.Worksheet
getPlatinum = False
Set oXLApp = New Excel.Application
Set oXLWBook = oXLApp.Workbooks.Add
Set oXLWSheet = oXLWBook.Worksheets("Sheet1")
oXLWSheet.Cells(1, 1).Value = "Customer"
oXLWSheet.Cells(1, 2).Value = "Currency"
oXLWSheet.Cells(1, 3).Value = "Amount"
oXLWSheet.Cells.Item(1, 1).Font.Size = 12
oXLWSheet.Cells.Item(1, 2).Font.Size = 12
oXLWSheet.Cells.Item(1, 3).Font.Size = 12
oXLWSheet.Cells.Item(1, 1).Font.Bold = True
oXLWSheet.Cells.Item(1, 2).Font.Bold = True
oXLWSheet.Cells.Item(1, 3).Font.Bold = True
Set Cnxn = New ADODB.Connection
Cnxn.ConnectionString = "Data Source=" & ServerId
& ";" & _
"User ID=" & UserId & ";Password=" & UserPassword
& ";Initial Catalog=" & CompanyId & ";"
Cnxn.Open
Journal_no = "ACSR0305001"
Set rstAP = New ADODB.Recordset
strSQL1 = "SELECT AMOUNT, ARTRXAGE.NAT_CUR_CODE,
ADDRESS_NAME FROM ARTRXAGE, ARMASTER " & _
" Where TRX_TYPE = 2031 And PAID_FLAG = 0 "
& _
" AND ARMASTER.CUSTOMER_CODE =
ARTRXAGE.CUSTOMER_CODE" & _
" ORDER BY ADDRESS_NAME"
rstAP.Open strSQL1, Cnxn, adOpenDynamic,
adLockPessimistic, adCmdText
rowNo = 2
Do Until rstAP.EOF
oXLWSheet.Cells(rowNo, 1).Value = rstAP!
ADDRESS_NAME
oXLWSheet.Cells(rowNo, 2).Value = rstAP!
ADDRESS_NAME & " -- " & rstAP!NAT_CUR_CODE
oXLWSheet.Cells(rowNo, 3).Value = rstAP!amount
rstAP.MoveNext
rowNo = rowNo + 1
Loop
oXLWSheet.Activate
Selection.Subtotal GroupBy:=2, Function:=xlSum,
TotalList:=Array(3)
oXLWSheet.Range(oXLWSheet.Cells.Item(1, 1),
oXLWSheet.Cells.Item(rowNo - 1, 3)).Columns.AutoFit
oXLApp.Visible = True
oXLWBook.Close
oXLApp.Quit
Set oXLWSheet = Nothing
Set oXLWBook = Nothing
Set oXLApp = Nothing
rstAP.Close
Set rstAP = Nothing
Cnxn.Close
Set Cnxn = Nothing
getPlatinum = True
MsgBox ("Finished")
Exit Function
ErrorHandler:
If Not rstAP Is Nothing Then
If rstAP.State = adStateOpen Then rstAP.Close
End If
Set rstAP = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Number & " : " & Err.Source & "-->" &
Err.Description, , "Error"
End If
End Function 4 9514
Hi Nelson,
Even for me this looks very much to VB6 code, either you have to change it
to more VB.net I think or else (if it is VB6) I think that it is better to
try to find help for this error in a classic VB newsgroup
Microsoft.public.vb* (there are a lot)
I hope this helps?
Cor
"ne*********@tristateww.com" <an*******@discussions.microsoft.com> schreef
in bericht news:07****************************@phx.gbl... Dear all, I wrote the VB code in a "button press event" as below in which is retrieve data from SQL server and insert the data into Excel. After that, I would call Excel "subtotal" API to build a subtotal figures. For first time, it is working fine. But in the second time, I try to execute the event again. Whenever it runs the command "Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3)", it always raises the error "Err 91 : Object variable or With block variable not set". Please advise. Thanks & Regards
Public Function getPlatinum() On Error GoTo ErrorHandler Dim rstAP As ADODB.Recordset Dim Cnxn As ADODB.Connection Dim strCnxn As String Dim strSQL1 As String Dim rowNo As Integer
Dim oXLApp As Excel.Application Dim oXLWBook As Excel.Workbook Dim oXLWSheet As Excel.Worksheet
getPlatinum = False Set oXLApp = New Excel.Application Set oXLWBook = oXLApp.Workbooks.Add Set oXLWSheet = oXLWBook.Worksheets("Sheet1")
oXLWSheet.Cells(1, 1).Value = "Customer" oXLWSheet.Cells(1, 2).Value = "Currency" oXLWSheet.Cells(1, 3).Value = "Amount" oXLWSheet.Cells.Item(1, 1).Font.Size = 12 oXLWSheet.Cells.Item(1, 2).Font.Size = 12 oXLWSheet.Cells.Item(1, 3).Font.Size = 12 oXLWSheet.Cells.Item(1, 1).Font.Bold = True oXLWSheet.Cells.Item(1, 2).Font.Bold = True oXLWSheet.Cells.Item(1, 3).Font.Bold = True
Set Cnxn = New ADODB.Connection Cnxn.ConnectionString = "Data Source=" & ServerId & ";" & _ "User ID=" & UserId & ";Password=" & UserPassword & ";Initial Catalog=" & CompanyId & ";" Cnxn.Open
Journal_no = "ACSR0305001" Set rstAP = New ADODB.Recordset
strSQL1 = "SELECT AMOUNT, ARTRXAGE.NAT_CUR_CODE, ADDRESS_NAME FROM ARTRXAGE, ARMASTER " & _ " Where TRX_TYPE = 2031 And PAID_FLAG = 0 " & _ " AND ARMASTER.CUSTOMER_CODE = ARTRXAGE.CUSTOMER_CODE" & _ " ORDER BY ADDRESS_NAME"
rstAP.Open strSQL1, Cnxn, adOpenDynamic, adLockPessimistic, adCmdText rowNo = 2 Do Until rstAP.EOF oXLWSheet.Cells(rowNo, 1).Value = rstAP! ADDRESS_NAME oXLWSheet.Cells(rowNo, 2).Value = rstAP! ADDRESS_NAME & " -- " & rstAP!NAT_CUR_CODE oXLWSheet.Cells(rowNo, 3).Value = rstAP!amount rstAP.MoveNext rowNo = rowNo + 1 Loop oXLWSheet.Activate
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(3) oXLWSheet.Range(oXLWSheet.Cells.Item(1, 1), oXLWSheet.Cells.Item(rowNo - 1, 3)).Columns.AutoFit oXLApp.Visible = True oXLWBook.Close oXLApp.Quit Set oXLWSheet = Nothing Set oXLWBook = Nothing Set oXLApp = Nothing
rstAP.Close Set rstAP = Nothing
Cnxn.Close Set Cnxn = Nothing getPlatinum = True MsgBox ("Finished") Exit Function
ErrorHandler:
If Not rstAP Is Nothing Then If rstAP.State = adStateOpen Then rstAP.Close End If Set rstAP = Nothing
If Not Cnxn Is Nothing Then If Cnxn.State = adStateOpen Then Cnxn.Close End If Set Cnxn = Nothing
If Err <> 0 Then MsgBox Err.Number & " : " & Err.Source & "-->" & Err.Description, , "Error" End If
End Function
* "Cor" <no*@non.com> scripsit: Even for me this looks very much to VB6 code, either you have to change it
Seems to be VB6 code.
;->
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
I thought here is for VB code whatever which version.
Nelson -----Original Message----- * "Cor" <no*@non.com> scripsit: Even for me this looks very much to VB6 code, either
you have to change it Seems to be VB6 code.
;->
-- Herfried K. Wagner [MVP] <http://www.mvps.org/dotnet> .
* "ne*********@tristateww.com" <an*******@discussions.microsoft.com> scripsit: I thought here is for VB code whatever which version.
As the name of this group says, it's a VB.NET group
("dotnet.languages.vb"). The VB1-6 groups can be found in the
microsoft.public.vb.* hierarchy.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hung Jung Lu |
last post by:
Hi,
Does anybody know where this term comes from?
"First-class object" means "something passable as an argument in a
function call", but I fail to see the connection with "object class"
or...
|
by: Michael McCracken |
last post by:
Hi, I have a problem with unittest.TestCase that I could really use
some help with.
I have a class File in module File. The important thing about File for
this discussion is that it's simple -...
|
by: Lauren Quantrell |
last post by:
I get the following error:
"Object variable or Width block variable not set error"
trying to run this in my Access2000 .ADP database:
CurrentDb.Properties.Append...
|
by: Mark Neilson |
last post by:
1. What is the best way to make a single instance of my top level class
(DLL) internally available to all other members of the assembly? The top
level object is where all other access is made in...
|
by: Neo Geshel |
last post by:
I am trying to deal with an image in code-behind. I consistently get the
following error:
Server Error in '/' Application.
Object variable or With block variable not set.
Description: An...
|
by: petermichaux |
last post by:
Hi,
I have been using the following line of code to create an object called
"Serious" if it doesn't already exist.
if (Serious == null) {var Serious = {};}
This works in the scripts I use...
|
by: Richard Hollenbeck |
last post by:
I've marked the line in this subroutine where I've been getting this error.
It may be something stupid but I've been staring at this error trying to fix
it for over an hour. I'm pretty sure the...
|
by: abhijmenbumca07 |
last post by:
Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
|
by: BrianAdev |
last post by:
Why It throw an error of <Object variable or With block variable not set>
set objAccess = GetObject(strMdbPath)
objAccess.DoCmd.SetWarning False
objAccess.DoCmd.OpenReport strReportName, 0
'It...
|
by: Newbie19 |
last post by:
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message:
Object variable or With block variable not set.
Description: An unhandled...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |