Solved

Procedure in Access will not place data on excel sheet

Posted on 2011-03-13
6
395 Views
Last Modified: 2012-06-21
vba 2003
access 2003, excel 2003

I'm running a procedure from access and passing variables to the procedure in access. as shown below..
Public Sub cmdCreatePrebuilt_Click()
Dim strSeg As Variant
Dim strFam As Variant
Dim strCat As Variant
         
      strSeg = ComboBox1.Text
      strFam = ComboBox2.Text
       strCat = ComboBox3.Text
       
       
       
Dim remoteApp As Access.Application
Set remoteApp = New Access.Application
remoteApp.OpenCurrentDatabase "C:\Program Files\Crs_iCart\Enterprise_Reporting_Backend.mdb", False 'you may need to change the false into true
remoteApp.Visible = True
remoteApp.Run "CallExportSeg", strSeg, strFam, strCat
 remoteApp.CloseCurrentDatabase
 Set remoteApp = Nothing
       
       
        ' restore the old cursor or else you may never get it back
        MsgBox "Done", vbInformation, "Export Segment:Family:Category"
   
End Sub

The procedure will run but no data is posted to the excel sheet


A sheet is being created but no data is placed in the sheet ?


Thanks
fordraiders
procedure in access:
Public Sub ExportSegFamCat(strSeg As String, strFam As String, strCat As String)

Dim strsql As String, qd As DAO.QueryDef
Set qd = CurrentDb.QueryDefs("qrySegFamCat")
On Error GoTo ExportSegFamCat_Err

strsql = "SELECT dbo_WwgExtraChgo.material_no, dbo_WwgExtraChgo.long_description, dbo_WwgExtraChgo.short_description, dbo_WwgExtraChgo.current_catalog_page_no, "
strsql = strsql & "dbo_WwgExtraChgo.sales_status, dbo_WwgExtraChgo.condensed_mfr_model_no, dbo_BrandInformation.brand_name, "
strsql = strsql & "dbo_BrandInformation.private_label, dbo_WwgExtraChgo.green_material_flag, dbo_WwgExtraChgo.van_eligible, "
strsql = strsql & "dbo_WwgExtraChgo.segment_name, dbo_WwgExtraChgo.family_name, dbo_WwgExtraChgo.category_name"
strsql = strsql & " FROM dbo_WwgExtraChgo LEFT JOIN dbo_BrandInformation ON dbo_WwgExtraChgo.brand_no = dbo_BrandInformation.brand_no"
strsql = strsql & " WHERE dbo_WwgExtraChgo.segment_name = '" & strSeg & "' AND dbo_WwgExtraChgo.family_name = '" & strFam & "' AND dbo_WwgExtraChgo.category_name = '" & strCat & "' "
qd.SQL = strsql

DoCmd.TransferSpreadsheet acExport, 8, "qrySegFamCat", "C:\Program Files\Crs Enterprise\iFinal\Prebuilt_Export\PreBuilt_Export.xls", True, ""
qd.Close
Set qd = Nothing
ExportSegFamCat_Exit:
    Exit Sub
ExportSegFamCat_Err:
    If Err.Number = "3010" Then
MsgBox "The Excel Sheet is Already Open. Close The Open Workbook", vbCritical, "Error Exporting Prebuilt"
Exit Sub
End If
Resume ExportSegFamCat_Exit

End Sub

Open in new window

0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35122785
1) Declare the variables as String instead of variants in cmdCreatePrebuilt_Click
2) Debug print the variables in ExportSegFamCat and see if the values are being passed.

We will take it form there.

Sid
0
 
LVL 6

Expert Comment

by:TinTombStone
ID: 35123173
Rather than have one database open another then call a procedure to run a query

Why not just build the query in the first database to get the data from the second?

strsql = "SELECT dbo_WwgExtraChgo.* FROM Clients
 IN 'C:\Program Files\Crs_iCart\Enterprise_Reporting_Backend.mdb';"

Seems a lot easier than messing about calling secondary procedures
0
 
LVL 3

Author Comment

by:fordraiders
ID: 35124591
moteApp.Run "CallExportSeg", strSeg, strFam, strCat <-----I get an illegal dunction call here  <-------------
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35125110
Ah!

Unfortunately I don't have access to ACCESS at the moment but I think I know what the problem is. Instead of using

remoteApp.Run

use

remoteApp.DoCmd.RunMacro

Sid
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35126507
Or use Run but call the actual subroutine itself directly. Mind you, if you are doing this from Excel, there's no need I can see to involve Access itself - just use ADO to run the query against the db.
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 35133071
THANKS
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question