Results 1 to 6 of 6

Thread: need help with syntax of ado.recordset.addnew function

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    9

    Talking need help with syntax of ado.recordset.addnew function

    All I need is the correct syntex for the adoOrder.recordset.addnew line:

    Private Sub cmdCartit_Click()
    'this button is supposed to take whatever
    'was ordered from item listed and put it in cart
    ' by creating a temporary database that will be seen on
    'the final form

    Dim Quantity As String, ID As String, Product As String, Price As String, ExtendedPrice As String

    'grab the information off the GUI

    Quantity = txtQuantity.Text
    ID = lblID.Caption
    Product = lblToolOrdered.Caption
    Select Case optDealerOption(index).Value = True
    Case index = 0
    Price = lblPrice(2).Caption
    Case index = 1
    Price = lblPrice(1).Caption
    Case index = 2
    Price = lblPrice(0).Caption
    End Select
    ExtendedPrice = lblExtendedPrice.Caption

    'use the ado control to enter data into feild.
    adoOrder.Recordset.AddNew ([fldID],[ID] & [fldProduct],[Product] & [fldPrice], [Price] & [fldExtendedPrice],
    [ExtendedPrice])

    You can assume that the items in the brackets with fldprefix are the feilds of the db
    and that the second[*] are supposed to be the strings created above.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    If you want to add more than one field at a time then the AddNew method expects two arrays. One for the fields and one for the field values.

    adoOrder.Recordset.AddNew Array("fldID","fldProduct", "fldPrice", "fldExtendedPrice") , Array(ID,Product, Price, ExtendedPrice)

    You can of course use a variable and load it yourself. Also you don't need to specify the field names, ordinal positions are acceptable.

    Dim aFields(3) as Long

    aFields(0) = 0
    aFields(1) = 1
    aFields(2 = 2
    aFields(3)= 3

    adoOrder.Recordset.AddNew aFields , Array(ID,Product, Price, ExtendedPrice)

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    9

    Unhappy now getting syntax error here.

    here's what I have now


    Private Sub cmdCartit_Click()
    'this button is supposed to take whatever
    'was ordered from item listed and put it in cart
    ' by creating a temporary database that will be seen on
    'the final form
    Dim Quantity As Integer, ID As String, Product As String, Price As Currency, ExtendedPrice As Currency

    'grab the information off the GUI

    Quantity = txtQuantity.Text
    ID = lblID.Caption
    Product = lblToolOrdered.Caption
    Select Case optDealerOption(index).Value = True
    Case index = 0
    Price = lblPrice(2).Caption
    Case index = 1
    Price = lblPrice(1).Caption
    Case index = 2
    Price = lblPrice(0).Caption
    End Select
    ExtendedPrice = lblExtendedPrice.Caption

    'use the ado control to enter data into feild.
    Dim aFields(4) As Long

    aFields(0) = fldID
    aFields(1) = fldProduct
    aFields(2) = fldPrice
    aFields(3) = fldQuantity
    aFields(4) = fldExtendedPrice

    adoOrder.Recordset.AddNew aFields(0 To 4) , Array(ID, Product, Price, Quantity, ExtendedPrice)

    Getting a syntax err for the ado statement. Anybody no what's missing?

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    First of all, in your statement

    adoOrder.Recordset.AddNew aFields(0 To 4) , Array(ID, Product, Price, Quantity, ExtendedPrice)

    change aFields(0 to 4) to just aFields.

    Second your statements

    aFields(0) = fldID
    aFields(1) = fldProduct ...

    What are fldId, fldProduct etc... are these constants, variables?

    Your field array must hold either the name of the field or its ordinal position.

  5. #5
    Addicted Member E-Link's Avatar
    Join Date
    Nov 2001
    Location
    INA
    Posts
    242
    VB Code:
    1. Private Sub cmdCartit_Click()
    2.  
    3. 'this button is supposed to take whatever
    4. 'was ordered from item listed and put it in cart
    5. ' by creating a temporary database that will be seen on
    6. 'the final form
    7. Dim Quantity As Integer, ID As String, Product As String, Price As Currency, ExtendedPrice As Currency
    8.  
    9. 'grab the information off the GUI
    10.  
    11. Quantity = txtQuantity.Text
    12. ID = lblID.Caption
    13. Product = lblToolOrdered.Caption
    14. Select Case optDealerOption(index).Value = True
    15. Case index = 0
    16. Price = lblPrice(2).Caption
    17. Case index = 1
    18. Price = lblPrice(1).Caption
    19. Case index = 2
    20. Price = lblPrice(0).Caption
    21. End Select
    22. ExtendedPrice = lblExtendedPrice.Caption
    23.  
    24.  
    25. adoOrder.Recordset.AddNew
    26.  
    27. adoOrder!fldID = ID
    28. adoOrder!fldProduct = Product
    29. adoOrder!fldPrice = Price
    30. adoOrder!fldQuantity = Quantity
    31. adoOrder!fldExtendedPrice = ExtendedPrice
    32.  
    33. adoOrder.Recordset.Update
    34.  
    35. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    9

    thanks for all your help still getting a bug

    fld* are the feild names of my blank access database. here's what I got now:

    Private Sub cmdCartit_Click()
    'this button is supposed to take whatever
    'was ordered from item listed and put it in cart
    ' by creating a temporary database that will be seen on
    'the final form
    Dim Quantity As Integer, ID As String, Product As String, Price As Currency, ExtendedPrice As Currency

    'grab the information off the GUI

    Quantity = txtQuantity.Text
    ID = lblID.Caption
    Product = lblToolOrdered.Caption
    Select Case optDealerOption(index).Value = True
    Case index = 0
    Price = Val(lblPrice(2).Caption)
    Case index = 1
    Price = Val(lblPrice(1).Caption)
    Case index = 2
    Price = Val(lblPrice(0).Caption)
    End Select
    ExtendedPrice = Val(lblExtendedPrice.Caption)

    'use the ado control to enter data into feild.

    'use the ado control to enter data into feild.
    Dim aFields(4) As Long

    aFields(0) = fldID
    aFields(1) = fldProduct
    aFields(2) = fldPrice
    aFields(3) = fldQuantity
    aFields(4) = fldExtendedPrice

    adoOrder.Recordset.AddNew aFields, Array(ID, Product, Price, Quantity, ExtendedPrice)


    I'm getting "Object variable or withblock variable not set"
    as my bug. on the adoOrder.recordset.addnew line

    John

Posting Permissions

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



Click Here to Expand Forum to Full Width