Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHAPED RecordSet Adding New Records

Status
Not open for further replies.

bbrendan

IS-IT--Management
Dec 13, 2001
109
GB
Hi,

Ive been playing around with the ms datashape command, and have no problems with editing an existing record, in either the MASTER or DETAIL tables.

I have used the VB wizard to create via ADO code. Once I overcome this hurdle I'd like to then modfiy it heavily to suit my application. Which is just an order entry program.

My Question is.
I want to add a new record, first filling in the MASTER Record, and then want to add the details like:
Product
Qty
Price.

BUT, when I save it wont save the details with the Header record. I think this is because the Detail Records do not have an OrderID to save with it, this is because when I add a new record it doesnt have an OrderID to associate with.

How would I code up to allow a new record to save both the Header and Detail parts at the same time?

My code is:
---------------------------------------------------------------
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDataShape;Data PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND2000.MDB;"

Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "SHAPE {select CustomerID,EmployeeID,Freight,OrderDate,OrderID,RequiredDate,ShipAddress,ShipCity,ShipCountry,ShipName,ShippedDate,ShipPostalCode,ShipRegion,ShipVia from Orders} AS ParentCMD APPEND ({select Discount,OrderID,ProductID,Quantity,UnitPrice from [Order Details] } AS ChildCMD RELATE OrderID TO OrderID) AS ChildCMD", db, adOpenStatic, adLockOptimistic

Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next

Set grdDataGrid.DataSource = adoPrimaryRS("ChildCMD").UnderlyingValue

mbDataChanged = False
End Sub
---------------------------------------------------------------------
For adding a Record it is
---------------------------------------------------------------------
Private Sub cmdAdd_Click()
On Error GoTo AddErr
With adoPrimaryRS
If Not (.BOF And .EOF) Then
mvBookMark = .Bookmark
End If
.AddNew
lblStatus.Caption = "Add record"
mbAddNewFlag = True
SetButtons False
End With

Exit Sub
AddErr:
MsgBox Err.Description
End Sub
---------------------------------------------------------------------

Thanks
Brendan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top