xiaoan614 发表于 2007-7-12 22:40

至少一个参数没有被指定

<P>我在access中用VBA代码写导入到excle的问题时,总提示“至少一个参数没有被指定”,查询过很多资料,有的说时不能在查询中设置查询参数,只能直接赋值,具体代码如下,请指点:</P>
<P>===============================<BR>Private Sub 导出到Excel_Click()<BR>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<BR>strSQL = "SELECT * FROM QUOTE_MAIN " <BR>strSQL = strSQL &amp; "Where QUOTE_NO_TIMES =" &amp; Me.QUOTE_NO_TIMES &amp; ";" <BR>Rec.Open strSQL, Conn, adOpenStatic, adLockOptimistic<BR>i = 1: j = 9<BR>   <BR>xlsheet.Name = Me.QUOTE_NO<BR>xlApp.Visible = True        '显示<BR>    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<BR>    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:" &amp; Chr(64 + Rec.Fields.Count) &amp; 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:" &amp; Chr(64 + Rec.Fields.Count) &amp; 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<BR>    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.ActiveCell.FormulaR1C1 = "ISSUE ORDER"<BR>    xlApp.Range("I3").Select<BR>    xlApp.ActiveCell.FormulaR1C1 = ISSUE_ORDER<BR>    <BR>    xlApp.Range("H4").Select<BR>    xlApp.ActiveCell.FormulaR1C1 = "DATE"<BR>    xlApp.Range("I4").Select<BR>    xlApp.ActiveCell.FormulaR1C1 = Format(DATE, "YYYY-MM-DD")<BR>    With xlsheet<BR>        .Range("A3:I7").Font.Bold = True<BR>         '标题字体加粗<BR>    End With<BR>    <BR>    xlApp.Rows("3:7").Select<BR>    With xlApp.Selection.Font<BR>        .Name = "Arial"<BR>        .Size = 10<BR>        .Strikethrough = False<BR>        .Superscript = False<BR>        .Subscript = False<BR>        .OutlineFont = False<BR>        .Shadow = False<BR>        .Underline = xlUnderlineStyleNone<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>       <BR>    '设置边框<BR>    xlApp.Range("A" &amp; j &amp; ":" &amp; Chr(64 + Rec.Fields.Count) &amp; Rec.RecordCount + j).Select<BR>    xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone<BR>    xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone<BR>    With xlApp.Selection.Borders(xlEdgeLeft)<BR>        .LineStyle = xlContinuous<BR>        .Weight = xlThin<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    With xlApp.Selection.Borders(xlEdgeTop)<BR>        .LineStyle = xlContinuous<BR>        .Weight = xlThin<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    With xlApp.Selection.Borders(xlEdgeBottom)<BR>        .LineStyle = xlContinuous<BR>        .Weight = xlThin<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    With xlApp.Selection.Borders(xlEdgeRight)<BR>        .LineStyle = xlContinuous<BR>        .Weight = xlThin<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    With xlApp.Selection.Borders(xlInsideVertical)<BR>        .LineStyle = xlContinuous<BR>        .Weight = xlThin<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    With xlApp.Selection.Borders(xlInsideHorizontal)<BR>        .LineStyle = xlContinuous<BR>        .Weight = xlThin<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    <BR>    '自动换行<BR>    With xlApp.Selection<BR>        .VerticalAlignment = xlCenter<BR>        .WrapText = True<BR>        .Orientation = 0<BR>        .AddIndent = False<BR>        .ShrinkToFit = False<BR>        .ReadingOrder = xlContext<BR>    End With<BR>    <BR>    '设置字体<BR>    With xlApp.Selection.Font<BR>        .Name = "Arial"<BR>        .Size = 9<BR>        .Strikethrough = False<BR>        .Superscript = False<BR>        .Subscript = False<BR>        .OutlineFont = False<BR>        .Shadow = False<BR>        .Underline = xlUnderlineStyleNone<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    <BR>    With xlsheet<BR>        '设置列标题<BR>        For m = 0 To Rec.Fields.Count - 1<BR>            .Cells(j, m + 1) = Rec.Fields(m).Name<BR>        Next<BR>        '设置表主体内容<BR>         Do While Not Rec.EOF<BR>            For n = 0 To Rec.Fields.Count - 1<BR>                  .Cells(i + j, n + 1) = Rec.Fields(n)<BR>            Next<BR>            i = i + 1<BR>            Rec.MoveNext<BR>         Loop<BR>    End With<BR>    <BR>    xlApp.Range(("A" &amp; Rec.RecordCount + j + 2), ("J" &amp; Rec.RecordCount + j + 2)).Select<BR>    xlApp.ActiveCell.FormulaR1C1 = "NOTE:"<BR>    xlApp.Selection.Merge<BR>    '设置字体<BR>    With xlApp.Selection.Font<BR>        .Name = "Arial"<BR>        .Size = 9<BR>        .Strikethrough = False<BR>        .Superscript = False<BR>        .Subscript = False<BR>        .OutlineFont = False<BR>        .Shadow = False<BR>        .Underline = xlUnderlineStyleNone<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    <BR>    xlApp.Range(("A" &amp; Rec.RecordCount + j + 3), ("J" &amp; Rec.RecordCount + j + 3)).Select<BR>    xlApp.ActiveCell.FormulaR1C1 = NOTE<BR>    xlApp.Selection.Merge<BR>    '设置字体<BR>    With xlApp.Selection.Font<BR>        .Name = "Arial"<BR>        .Size = 9<BR>        .Strikethrough = False<BR>        .Superscript = False<BR>        .Subscript = False<BR>        .OutlineFont = False<BR>        .Shadow = False<BR>        .Underline = xlUnderlineStyleNone<BR>        .ColorIndex = xlAutomatic<BR>    End With<BR>    <BR>    Rec.close<BR>    <BR>    Set Rec = Nothing<BR>    Set Conn = Nothing<BR>    Set xlApp = Nothing<BR>    Set xlsheet = Nothing<BR>    <BR>Exit_OutputToExcel:<BR>    Exit Sub<BR>Err_OutputToExcel:<BR>    Set Rec = Nothing<BR>    Set Conn = Nothing<BR>    Set xlApp = Nothing<BR>    Set xlsheet = Nothing<BR>    MsgBox Err.description<BR>    Resume Exit_OutputToExcel<BR>End Sub<BR>==================================<BR>望高人指点啊,我这个问题已经困扰我好几天了,呜呼……</P>

bygg 发表于 2007-7-13 18:06

这么多,错误显示到哪一行的?&gt;

xiaoan614 发表于 2007-7-13 21:51

<P>我想应该是查询语句的问题,但是怎么改,问题在哪实在是弄不懂了,如果不加查询条件是可以的,但关键没查询条件查询出的数据非常多,而且不能满足需求啊。<BR></P>
<P>strSQL = "SELECT * FROM QUOTE_MAIN " <BR>strSQL = strSQL &amp; "Where QUOTE_NO_TIMES =" &amp; Me.QUOTE_NO_TIMES &amp; ";" </P>

zkqbp 发表于 2007-7-14 08:04

<P>我用isnull()函数在查询语句中,程序运行时也出现【至少一个参数没有被指定】的提示,是否access的版本太低的原因吧?请问各位高手[em01]</P>

页: [1]

编程论坛