By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Recordset from Access to Excel based on a Query with combo box criteria

P: 3
Hi there how r u .I would really appriciate ur concern regarding checking out this code.
its beind a command button and i am have a combo box selecing a query criteria and then pressing the button to take care recoredset from access to excel.
i have checked the code in any ways its working fine but when i use the combo box criteria
forms!formname!combobox
in the query the code breaks down at

rst.open a """""""""""gives me error one or two parameter values are not entered"""""""""""""""

AT BREAK POINT IN IMMEDIATE WINDOW WHEN U PUT UR MOUSE OVER COMBO IT DOES PASS THE VALUE BUT WHEN I COMES TO
rst.open a
error occurs

I have already tried
a = a + " HAVING (((tblndwpcsvw.CAT) = " & Me.Combo3 & "))"
instead of
a = a + " HAVING (((tblndwpcsvw.CAT) = [Forms]![tblndwpcsvw]![Combo3]))"

thankxxxxxxxxxxxxxx and have a nice day bbye

NOTE:Copied the SQL from query
NOTE:"""""""""""""""""the query involve a crosstab query thats why the explicit parameter is required""""""""""



Private Sub Command1_Click()


Dim cnn As ADODB.Connection

Set cnn = CurrentProject.Connection
Dim rst As New ADODB.Recordset
rst.ActiveConnection = cnn
Dim a As String

a = " PARAMETERS [forms]![tblndwpcsvw]![combo3] Text ( 255 );"

a = a + " SELECT tblndwpcsvw.CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]"

a = a + " FROM tblndwpcsvw INNER JOIN [PROFILING Query] ON tblndwpcsvw.PCS2 = [PROFILING Query].CAT"

a = a + " GROUP BY tblndwpcsvw.CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]"

a = a + " HAVING (((tblndwpcsvw.CAT) = [Forms]![tblndwpcsvw]![Combo3]))"

a = a + " ORDER BY tblndwpcsvw.CAT, [PROFILING Query].WK;"


rst.Open a

Dim xl As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet

Set xl = CreateObject("excel.application")

Set xlbook = GetObject("c:\abc.xls")

xl.Visible = True


xlbook.Windows(1).Visible = True

Set xlsheet = xlbook.Worksheets(1)

xlsheet.Range("b3").CopyFromRecordset rst


Set xl = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
rst.Close
Set rst = Nothing

End Sub
Jul 6 '07 #1
Share this Question
Share on Google+
4 Replies


JKing
Expert 100+
P: 1,206
Could you post the error number and description for the error you are receiving?
Jul 6 '07 #2

P: 3
Thank you very much for checking out this code.please check below i am receiving this error in the msg box.
talk to u later take care and have a nice day
bbye



Run-time error '-2147217904(80040e10)':
No value given for one or more required parameters.
Jul 6 '07 #3

P: 3
Hi JKING thank u very much i lost lots of time on this SQL but u helped me out by pointing me to work on the error number so i came across this sql and its working now
its passing the value in the immediate window
but now i am getting this error

"syntex error in parameter clause"

the sql i am using now

a = " PARAMETERS " & [Forms]![tblndwpcsvw]![Combo3] & " Text ( 255 )" + " SELECT tblndwpcsvw.CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]" + " FROM tblndwpcsvw INNER JOIN [PROFILING Query] ON tblndwpcsvw.PCS2 = [PROFILING Query].CAT" + " GROUP BY tblndwpcsvw.CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]" + " HAVING (((tblndwpcsvw.CAT) = " & Me.Combo3 & "))" + " ORDER BY tblndwpcsvw.CAT, [PROFILING Query].WK;"

rst.Open a
Jul 6 '07 #4

JKing
Expert 100+
P: 1,206
Have you tried running it with just this:

Expand|Select|Wrap|Line Numbers
  1. a = "SELECT tblndwpcsvw.CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]" + " FROM tblndwpcsvw INNER JOIN [PROFILING Query] ON tblndwpcsvw.PCS2 = [PROFILING Query].CAT" + " GROUP BY tblndwpcsvw.CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]" + " HAVING (((tblndwpcsvw.CAT) = " & Me.Combo3 & "))" + " ORDER BY tblndwpcsvw.CAT, [PROFILING Query].WK;"
  2.  
As you've said it is receiving the value from the combo box. I don't believe you need to specify the control as a parameter in the query. This should solve your error.

Another note without knowing exactly whats in your tables or queries or the purpose behind them I can't say this for certain but it does seem like this query string is unnecessarily long.
Would the following not produce the same results?
Expand|Select|Wrap|Line Numbers
  1. a = "SELECT [Profiling Query].CAT, [PROFILING Query].WK, [PROFILING Query].[2004], [PROFILING Query].[2005], [PROFILING Query].[2006]" + " FROM [Profiling Query] WHERE [Profiling Query].CAT = " & Me.Combo3 &  " ORDER BY [PROFILING Query].CAT, [PROFILING Query].WK;"
  2.  
Jul 6 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.