Solved

Procedure in Access will not place data on excel sheet

Posted on 2011-03-13
6
386 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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…

726 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