|
-
Dec 2nd, 2002, 05:30 PM
#1
Thread Starter
New Member
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.
-
Dec 2nd, 2002, 06:07 PM
#2
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)
-
Dec 2nd, 2002, 07:17 PM
#3
Thread Starter
New Member
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?
-
Dec 2nd, 2002, 08:02 PM
#4
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.
-
Dec 2nd, 2002, 08:47 PM
#5
Addicted Member
VB Code:
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
adoOrder.Recordset.AddNew
adoOrder!fldID = ID
adoOrder!fldProduct = Product
adoOrder!fldPrice = Price
adoOrder!fldQuantity = Quantity
adoOrder!fldExtendedPrice = ExtendedPrice
adoOrder.Recordset.Update
End Sub
-
Dec 3rd, 2002, 08:01 PM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|