Adding to recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Winchell
    New Member
    • Dec 2010
    • 2

    #1

    Adding to recordset

    I have a simple database table with a column called "Quantity". It stores the current quantity of various food items. In Excel, I want to allow the user to type in a number (say, 10) and add that number (10) to the current count in inventory in the database. The code I have is as follows:

    Code:
    dim rs as new recordset
    strSql = "select * from Bakery"
    strConnect = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" & ThisWorkbook.Path & "/Inventory.mdb;"
    set rs = createobject("ADODB.Recordset")
    rs.open strsql, strConnect, adOpenStatic, adLockPessimistic
    rs.Find "[Item] = '" & Me.ComboBox2 & "'"
    
    'I know the next line is wrong
    rs("Quantity") = Current Quantity + ComboBox3.Value
    
    rs.Update
    rs.close
    set rs = nothing
    end sub
    Any tips?
  • Matt Winchell
    New Member
    • Dec 2010
    • 2

    #2
    nevermind, solved my own problem

    Please ignore

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Line #9 is a problem because you have some type of variable (I can't determine from the code posted what kind) with a space in the name. Generally this is a bad idea, but it is supported. To access such a variable reliably simply surround it in brackets ([]) as in :
      Code:
      rs("Quantity") = [Current Quantity] + ComboBox3.Value
      PS. We're always glad when you manage to solve it yourself, but we also like to have answers posted where possible for the benefit of anyone else with a similar problem.

      Comment

      Working...