Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I love this site! It's so nice to know that there are so many people out there who are willing to share their knowledge..."

Geography

Where in the world do Tek-Tips members come from?

Runtime error '50290' application-defined - Acess 2007

JDT1900 (MIS)
24 Jun 12 21:30
Good morning all,

I have inherited an Access Database with some VBA (and yes I am terrible with VBA).

1) Upon running the Code in the database I get an error:
runtime error '50290' application-defined....

2) Upon debugging the Code it is falling over at the following line:
objSht.Cells(iRow, 3).Value = rst!netPrice

I have included the code below. Any thoughts?

Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim rst As Recordset
Dim iRow As Long
Dim Y(20) As String
Dim QBActive As Boolean

'--- open the workbook

Set objXL = New Excel.Application
objXL.Visible = True
Set objWkb = objXL.Workbooks.Open("C:\Greentree\Printblocks\Excel\QuantityBreaksTemplate.xltx")
Set objSht = objWkb.Worksheets("QuantityBreaks")

iRow = 2 ' as there is a header

Set rst = CurrentDb.OpenRecordset("SELECT StockItem.code, StockItem.description, INSellingPrice.netPrice, QuantityBreaksDiscount.price, QuantityBreaksDiscount.isActive, QuantityBreaksDiscount.quantity, StockItem.quantityAvailable FROM ((((QuantityBreaksDiscount RIGHT JOIN (INSellingPrice RIGHT JOIN StockItem ON INSellingPrice.myStockItem = StockItem.oid) ON QuantityBreaksDiscount.myINSellingPrice = INSellingPrice.oid) LEFT JOIN StockItem_allTreeZones ON StockItem.oid = StockItem_allTreeZones.stockItem_oid) LEFT JOIN TreeZone ON StockItem_allTreeZones.treeZone_oid = TreeZone.oid) LEFT JOIN Tree ON TreeZone.myTree = Tree.oid) LEFT JOIN Tree AS Tree_1 ON Tree.myTreeRoot = Tree_1.oid WHERE ((INSellingPrice.isActive)=True) AND ((Tree_1.name)='Product By Manufacturer') ORDER BY StockItem.code, QuantityBreaksDiscount.isActive, QuantityBreaksDiscount.quantity")

rst.MoveFirst

X = 0

Do While Not rst.EOF

X = X + 1
Y(X) = rst!code
QBActive = rst!isActive
If Y(X) = Y(X - 1) And QBActive = True Then
objSht.Cells(iRow - 1, (2 * X) + 3).Value = rst!quantity
objSht.Cells(iRow - 1, (2 * X) + 4).Value = rst!price
GoTo 10
End If
If Y(X) = Y(X - 1) Then GoTo 10
X = 1
Y(X) = rst!code

objSht.Cells(iRow, 1).Value = rst!code
objSht.Cells(iRow, 2).Value = rst!Description
objSht.Cells(iRow, 3).Value = rst!netPrice
objSht.Cells(iRow, 4).Value = rst!quantityAvailable
objSht.Cells(iRow, 5).Value = rst!quantity
objSht.Cells(iRow, 6).Value = rst!price

iRow = iRow + 1
10 rst.MoveNext
Loop

objSht.Columns("A:D").EntireColumn.AutoFit

If Dir("C:\Greentree\Printblocks\Excel\DailyPriceListReport.xlsx") <> "" Then
Kill ("C:\Greentree\Printblocks\Excel\DailyPriceListReport.xlsx")
End If

objWkb.SaveAs FileName:="C:\Greentree\Printblocks\Excel\DailyPriceListReport.xlsx", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
objXL.Quit

Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
rst.Close

DoCmd.Quit
End Sub
vbajock (Programmer)
25 Jun 12 11:44
What is the value of rst!netPrice when the error occurs?
vbajock (Programmer)
25 Jun 12 11:51
Also, make sure no one has the spreadsheet open when you run it.

Right before the line that bombs, insert this code:

If Application.Ready = True Then
MsgBox "Application is ready."
Else
MsgBox "Application is not ready."
End If

What do you get for a message?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close