DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: problem in update database using visual basic

  1. #1
    Join Date
    Jul 2007
    Posts
    15

    problem in update database using visual basic

    Hi everyone,

    I am new with microsoft visual basic. I want to create a form (included combo box and command button) in Dabase access 2007 used microsoft visual basic to update the sql statement based on the user's selection from the combo box. here is my code.

    Private Sub button1_Click()

    Dim selection As String
    selection = dropdownlist1.ItemsSelected
    Dim db As Database
    Dim sql As QueryDef
    Dim strSQL As String
    Set db = CurrentDb
    strSQL = "UPDATE Main SET City = " " WHERE Customer = " & selectLender & ";"
    Set sql = db.CreateQueryDef("strSQL")

    End Sub

    The problem is it doesn't update the database. Can anyone help me out? I am very appriciated.
    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this:
    Code:
    Dim SQL As String
    
    SQL = "UPDATE Main SET City = "" "" WHERE Customer = '" & DropDownList1.Text & "'"
    CurrentDb.Execute SQL
    Last edited by Phil Weber; 07-20-2007 at 07:56 PM.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jul 2007
    Posts
    15
    Thanks for a quick replying. I tried your code, then I got run time error '2185' "You can't reference a property or method for a control unless the control has the focus."

  4. #4
    Join Date
    Feb 2004
    Location
    Sydney, Australia
    Posts
    498
    Hard sometimes to separate ' from " on the screen.

    What are you trying to set City to ?

  5. #5
    Join Date
    Jul 2007
    Posts
    15
    Thank you for your help Phil, it works.

Similar Threads

  1. Database SQL and Apllication Visual Basic
    By Ahmed in forum VB Classic
    Replies: 0
    Last Post: 08-01-2002, 07:29 AM
  2. Replies: 5
    Last Post: 06-07-2002, 06:35 PM
  3. Replies: 1
    Last Post: 03-28-2002, 09:43 PM
  4. Replies: 6
    Last Post: 03-28-2001, 12:12 PM

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