Solved

Procedure in Access will not place data on excel sheet

Posted on 2011-03-13
6
358 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
6 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
Comment Utility
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
Comment Utility
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
Comment Utility
moteApp.Run "CallExportSeg", strSeg, strFam, strCat <-----I get an illegal dunction call here  <-------------
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:SiddharthRout
Comment Utility
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
Comment Utility
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
Comment Utility
THANKS
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now