Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Posts
    7

    Unanswered: Getting value from Combo Box

    I am trying to create a procedure to create an assemblies based on existing assemblies. For example, I want to change a Volvo to a BMW:

    Car Item Qty
    Volvo Blue 1
    Volvo A/C 1

    Change it to this:

    Car Item Qty
    BMW Blue 1
    BMW A/C 1

    So I created the procedure below:

    Private Sub Make_Copy_Click()

    Dim SQL As String
    Dim Copy As String

    'AddAssemblyCombo is a Combobox
    Copy = [AddAssemblyCombo].Value

    'Delete all rows from tempAssemblies table
    SQL = "delete * from tempAssemblies"
    CurrentDb.Execute SQL

    'Insert Assembly to copy into tempAssemblies
    SQL = "INSERT into tempAssemblies (CatID, ItemID, Qty, Sort) " _
    & "SELECT Assemblies.AssemCatalogID, Assemblies.[AssemItem ID], Assemblies.AssemQuantity, Assemblies.AssemSort " _
    & "FROM Assemblies " _
    & "WHERE (((Assemblies.AssemCatalogID) = Copy));"

    CurrentDb.Execute SQL

    DoCmd.OpenTable "tempAssemblies", acViewNormal

    End Sub


    Why do I get a too few parameters expected error?

    Thanks for any help.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    You have to concatenate the value of the variable into the string. Presuming it's a numeric data type:

    & "WHERE Assemblies.AssemCatalogID = " & Copy
    Paul

  3. #3
    Join Date
    Apr 2012
    Posts
    7
    Quote Originally Posted by pbaldy View Post
    You have to concatenate the value of the variable into the string. Presuming it's a numeric data type:

    & "WHERE Assemblies.AssemCatalogID = " & Copy
    & "WHERE Assemblies.AssemCatalogID = " & Copy[/QUOTE]

    Copy is a string.

    This gives me a blank table:

    & "WHERE Assemblies.AssemCatalogID = 'Copy';"

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    If it's a string:

    & "WHERE Assemblies.AssemCatalogID = '" & Copy & "'"
    Paul

  5. #5
    Join Date
    Apr 2012
    Posts
    7
    Thanks!! That works.

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Happy to help!
    Paul

Posting Permissions

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