Office中国论坛/Access中国论坛
标题:
至少一个参数没有被指定
[打印本页]
作者:
xiaoan614
时间:
2007-7-13 06:34
标题:
至少一个参数没有被指定
<
>我在access中用VBA代码写导入到excle的问题时,总提示“至少一个参数没有被指定”,查询过很多资料,有的说时不能在查询中设置查询参数,只能直接赋值,具体代码如下,请指点:</P>
<
><BR>===============================<BR>
rivate Sub 导出到Excel_Click()</P>
<P>On Error GoTo Err_OutputToExcel<BR>Dim xlApp As New Excel.Application<BR>Dim xlBook As Excel.Workbook<BR>Dim xlsheet As New Excel.Worksheet<BR>Dim Conn As New ADODB.Connection<BR>Dim Rec As New ADODB.Recordset<BR>Dim strSQL As String<BR>Dim i As Integer, j As Integer, m As Integer, n As Integer<BR> <BR>Set xlApp = CreateObject("Excel.Application")<BR>Set xlBook = xlApp.Workbooks.add<BR>Set xlsheet = xlBook.Worksheets(1)<BR>Set Conn = CurrentProject.Connection</P>
<P><FONT color=#ff0000>strSQL = "SELECT * FROM QUOTE_MAIN " <BR>strSQL = strSQL & "Where QUOTE_NO_TIMES =" & Me.QUOTE_NO_TIMES & ";"</FONT> </P>
<P>Rec.Open strSQL, Conn, adOpenStatic, adLockOptimistic</P>
<P>i = 1: j = 9<BR> <BR>xlsheet.Name = Me.QUOTE_NO<BR>xlApp.Visible = True '显示</P>
<P> With xlsheet<BR> .Columns("a:j").Font.Size = 10<BR> .Columns("a:j").VerticalAlignment = xlVAlignCenter '垂直居中<BR> .Columns("A:J").HorizontalAlignment = xlHAlignLeft '1列水平居中对齐<BR> End With</P>
<P> With xlsheet<BR> '设置列宽<BR> .Cells(1, 1).ColumnWidth = 13<BR> .Cells(1, 2).ColumnWidth = 20<BR> .Cells(1, 3).ColumnWidth = 6<BR> .Cells(1, 4).ColumnWidth = 7.5<BR> .Cells(1, 5).ColumnWidth = 15<BR> .Cells(1, 6).ColumnWidth = 10<BR> .Cells(1, 7).ColumnWidth = 6<BR> .Cells(1, 8).ColumnWidth = 15<BR> .Cells(1, 9).ColumnWidth = 9<BR> .Cells(1, 10).ColumnWidth = 15<BR> <BR> End With<BR> <BR> '设置表头<BR> xlApp.Range("A1:" & Chr(64 + Rec.Fields.Count) & 1).Select<BR> With xlApp.Selection<BR> .HorizontalAlignment = xlCenter<BR> .VerticalAlignment = xlCenter<BR> .WrapText = False<BR> .Orientation = 0<BR> .AddIndent = False<BR> .IndentLevel = 0<BR> .ShrinkToFit = False<BR> .ReadingOrder = xlContext<BR> .MergeCells = False<BR> End With<BR> xlApp.Selection.Merge<BR> <BR> xlApp.Range("A1:" & Chr(64 + Rec.Fields.Count) & 1).Select<BR> With xlApp.Selection<BR> .HorizontalAlignment = xlCenter<BR> .VerticalAlignment = xlCenter<BR> .WrapText = False<BR> .Orientation = 0<BR> .AddIndent = False<BR> .IndentLevel = 0<BR> .ShrinkToFit = False<BR> .ReadingOrder = xlContext<BR> .MergeCells = False<BR> End With<BR> xlApp.Selection.Merge<BR> <BR> xlApp.Range("A1").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "QUOTE SHEET"<BR> With xlApp.Selection.Font<BR> .Name = "Arial Black"<BR> .Size = 16<BR> .Strikethrough = False<BR> .Superscript = False<BR> .Subscript = False<BR> .OutlineFont = False<BR> .Shadow = False<BR> .Underline = xlUnderlineStyleNone<BR> .ColorIndex = xlAutomatic<BR> End With</P>
<P> xlApp.Range("A3").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "PRICE NO."<BR> xlApp.Range("B3").Select<BR> xlApp.ActiveCell.FormulaR1C1 = QUOTE_NO<BR> <BR> xlApp.Range("A4").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "PRICE TIMES"<BR> xlApp.Range("B4").Select<BR> xlApp.ActiveCell.FormulaR1C1 = QUOTE_TIMES<BR> <BR> xlApp.Range("A5").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "FOLLOW NO."<BR> xlApp.Range("B5").Select<BR> xlApp.ActiveCell.FormulaR1C1 = SALPME_FOLLOW_NO<BR> <BR> xlApp.Range("A6").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "FACTORY"<BR> xlApp.Range("B6").Select<BR> xlApp.ActiveCell.FormulaR1C1 = FACTORY<BR> <BR> xlApp.Range("A7").Select<BR> xlApp.ActiveCell.FormulaR1C1 = "CUSTOMER"<BR> xlApp.Range("B7").Select<BR> xlApp.ActiveCell.FormulaR1C1 = CUSTOMER<BR> <BR> xlApp.Range("H3").Select<BR> xlApp.ActiveCe
作者:
wang1950317
时间:
2007-7-13 16:53
<
>常常碰到这样的提示,太菜弄不懂,有时就无目的的查勘表和查询,总会发现和代码有关联的表或查询有小错。改正就好了。如果更改表中某一列的列标,更会出现这种情况,如果在某些特定的列中误输入反常的字符,也会出现。还待请有经验的老师们指点。</P>
作者:
sgrshh29
时间:
2007-7-13 19:22
<DIV class=quote><B>以下是引用<I>wang1950317</I>在2007-7-13 8:53:00的发言:</B><BR>
<
>常常碰到这样的提示,太菜弄不懂,有时就无目的的查勘表和查询,总会发现和代码有关联的表或查询有小错。改正就好了。如果更改表中某一列的列标,更会出现这种情况,如果在某些特定的列中误输入反常的字符,也会出现。还待请有经验的老师们指点。</P></DIV>
<p>对于这种格式固定的excel,我从来不用这种方法,一般是做个excel模板,只要把access中的数据粘贴过去,然后另存就可以了。既简单,又灵活,还可避免出错,代码也少。
作者:
zhengjialon
时间:
2007-7-13 19:51
看看查询中有没有参数:<FONT color=#ff0000>QUOTE_MAIN ,如果有是不行的.</FONT>
作者:
xiaoan614
时间:
2007-7-14 05:54
查询中没有QUOTE_MAIN啊,QUOTE_MAIN只是一个表
作者:
老鬼
时间:
2007-7-14 18:51
或许是<FONT color=#ff0000>QUOTE_NO_TIMES 数据类型的问题。</FONT>
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3