Consulting

Results 1 to 5 of 5

Thread: Solved: insert into

  1. #1

    Solved: insert into

    In the sub below i get an error:

    Run-time error '3061':

    too few parameters, expected 2.
    [VBA]Private Sub RUN_Click()
    Dim filename As Variant
    Dim daterecd As Variant
    Dim strSQL As String

    filename = txtFileName.Value
    daterecd = txtDateRecd.Value

    Set db = CurrentDb()

    strSQL = "INSERT into gwexport (filename, daterecd) Values (" & [filename] & ", " & [daterecd] & ")"
    Debug.Print strSQL


    db.Execute strSQL



    End Sub[/VBA]
    Table gwexport:
    filename is text
    daterecd is text

    Where am i going wrong?

    Let me know if you need more information.

    Thanks

  2. #2
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    Just a guess but you could try
    filename = Me.txtFileName.Value
    daterecd = Me.txtDateRecd.Value

    I think it hasn't resolved these 2 fields from the Form.

  3. #3
    Quote Originally Posted by orange
    Just a guess but you could try
    filename = Me.txtFileName.Value
    daterecd = Me.txtDateRecd.Value

    I think it hasn't resolved these 2 fields from the Form.
    Still the same result

  4. #4
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    257
    Location
    I have set up a small test of your issue. The problem is with the quotes.
    You need quotes to suuround the text values in the INSERT statement.
    Adjust as follows -- It works.

    strSQL = "INSERT into gwexport (filename, daterecd) Values ( '" & [filename] & "', '" & [daterecd] & "');"
    Last edited by orange; 05-09-2009 at 06:50 AM.

  5. #5
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    The quotes that orange is referring to are called data type qualifiers. Whenever you want to use VBA variables or object value references in a hard-coded SQL string, you have to wrap them with data qualifiers. For string values, you use single quotes, as illustrated above. For Dates, you use the pound sign (#), and for numbers you do not use any qualifier.

    Your code was failing because your lack of data qualifiers told SQL to expect numeric values for the parameters, but you are passing it string values.

    HTH
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •