Help needed with combo box and database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Help needed with combo box and database

  1. #1
    Join Date
    Mar 2005
    Posts
    49

    Help needed with combo box and database

    Hello,

    I am trying to write items added by a user to a combo box to a database, and I am getting an error doing this. The code is as shown below:

    Code:
    Dim Qstn As Database
    
        ' Modify this line to include the path to Northwind
        ' on your computer.
        Set Qstn = OpenDatabase(App.Path & "\RotorData.mdb")
    
        ' Delete employee records where title is Trainee.
        Qstn.Execute "Insert into Questions(Question) Values(Combo1.Text)"
        
        Qstn.Close

    Getting the following error:

    RunTime Error: '3061'
    Too few parameters Expected 1

    Help??

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    Given the syntax you're using, Combo1.Text cannot be properly evaluated. Try the following:

    Qstn.Execute "Insert into Questions (Question) Values ('" & Combo1.Text & "')"
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    Mar 2005
    Posts
    49
    Ya i did what you said, but still getting the same error. I am just trying to add what ever is entered in the combo box to a data base and populate the combo box with entries from the database each time the project is compiled. if there is any other way this can be done, I would really appreciate if anyone could share it with me.

  4. #4
    Join Date
    Dec 2003
    Posts
    2,750
    Well I don't see any problem with the syntax so it's likely a problem with the column name. Are you certain there is a column called Question in your Questions table? Is it spelled correctly?
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  5. #5
    Join Date
    Mar 2005
    Posts
    49
    Yes, it is spelled correctly. The data type I chose for the Question column is "text". Do you think that has something to do with this error??

  6. #6
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    see if this helps:

    http://support.microsoft.com/default...b;en-us;210244

    otherwise:
    http://support.microsoft.com/default...b;en-us;105171

    TIP: open the MSDN web page, and type 'error 3061' in the search box

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  7. #7
    Join Date
    Dec 2003
    Posts
    2,750
    Are there any other columns in the Questions table that require values in order to insert a row?

    If not, try hard-coding the value to make sure that the statement executes properly:

    Qstn.Execute "Insert into Questions (Question) Values ('Test')"
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  8. #8
    Join Date
    Mar 2005
    Posts
    49
    Hello pclement,

    Qstn.Execute "Insert into Questions(Question1) Values('Test')" works, but

    Qstn.Execute "Insert into Questions(Question1) Values(" & Combo1.Text & ")"

    does not.

  9. #9
    Join Date
    Dec 2003
    Posts
    2,750
    OK, try the following to see if it works (make sure to leave in the single quotes). If it fails, post the value of strSQL:

    Code:
    Dim strSQL As String
    
    strSQL = "INSERT INTO Questions (Question1) VALUES ('" & Combo1.Text & "')"
    Qstn.Execute strSQL
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  10. #10
    Join Date
    Mar 2005
    Posts
    49
    Thanks a lot Paul...it works !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center