|
-
Aug 7th, 2000, 08:52 AM
#1
Thread Starter
Member
Please Help!
Every time I try to add a new record to my database I get this error:
Run-Time Error: '-2147467259(80004005)':
You cannot Add or Change A record because a related record is required in table 'CUST'.
The code that it bombs on is:
Adodc1.Recordset.Update
The thing that kills me is that I am not updating the customer table, just the orders table. This program will run OK if I do not 'enforce referential intergrity' with the relationships between the tables in the database (in Access). The problem with that is that the customer # is not written to the orders table. It actually leaves that field blank.
I know that this should be easy to answer, but I am baffled. The other thing is that I am using Microsoft Jet 4.0, not 3.51. Every example in these two books I own uses 3.51, but VB 6.0 doesn't reckognize that version of Access.
Thak You for any help!
Joe
-
Aug 7th, 2000, 09:04 AM
#2
Junior Member
Joe:
Does the customer exists on the customer table when you are adding the order?, and if so what is your code to add it?
Chicho
-
Aug 7th, 2000, 09:38 AM
#3
Frenzied Member
You've got two choices.
1) remove referential integrity so that the existence of a record in ORDERS does not require a record to be in CUST
2) create a customer "Customer Undefined" and use that value as your default value for ORDERS. Of course, the user should be able to change the value to an actual customer (you may want to force this, making "Customer Undefined" a temporary value).
-
Aug 7th, 2000, 09:39 AM
#4
Thread Starter
Member
This is what my code looks Like:
Option Explicit
Dim ctl As Control
Private Sub Form_Load()
Adodc1.Recordset.AddNew
txtClient.Text = frmOrderNew.txtName.Text
txtClientID.Text = frmOrderNew.txtID.Text
txtPhone.Text = frmOrderNew.txtPhone.Text
txtFax.Text = frmOrderNew.txtFax.Text
txtWrittenBy.Text = frmOrderNew.txtEntered.Text
txtContact.Text = frmOrderNew.txtFName.Text & " " & frmOrderNew.txtLName.Text
txtSalesRep.Text = frmOrderNew.txtSalesRep.Text
txtDateIn.Text = Date
txtTimeIn.Text = Time
txtProofsDue.Text = Date + 1
txtDelivery.Text = Date + 7
End Sub
Private Sub cmdSubmit_Click()
Dim dbTest As Database
Dim iOrder As Integer
If txtProofsDue <> "__/__/__" Then
If Not IsDate(txtProofsDue) Then
MsgBox "Please Re-enter the date in the proofs due. (mm/dd/yy)", _
vbOKOnly + vbInformation, "Date Validation"
txtProofsDue.SetFocus
Exit Sub
End If
End If
If txtDelivery <> "__/__/__" Then
If Not IsDate(txtDelivery) Then
MsgBox "Please Re-enter the date of the delivery. (mm/dd/yy)", _
vbOKOnly + vbInformation, "Date Validation"
txtDelivery.SetFocus
Exit Sub
End If
End If
Adodc1.Recordset.Update
iOrder = MsgBox("Continue with this order?", vbYesNo + vbInformation, _
"Order Processing")
If iOrder = vbYes Then
For Each ctl In frmOrderNewSheet.Controls
If TypeOf ctl Is CheckBox Then
ctl.Value = 0
End If
Next
For Each ctl In frmOrderNewSheet.Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
txtClient.Text = frmOrderNew.txtName.Text
txtClientID.Text = frmOrderNew.txtID.Text
txtPhone.Text = frmOrderNew.txtPhone.Text
txtFax.Text = frmOrderNew.txtFax.Text
txtWrittenBy.Text = frmOrderNew.txtEntered.Text
txtContact.Text = frmOrderNew.txtFName.Text & " " & frmOrderNew.txtLName.Text
txtSalesRep.Text = frmOrderNew.txtSalesRep.Text
Tabs.TabEnabled(1) = True
Tabs.TabEnabled(2) = True
Else
MsgBox "Order Entered.", vbOKOnly + vbInformation, _
"Order Processing"
Unload Me
End If
End Sub
Private Sub form_Unload(Cancel As Integer)
Adodc1.Recordset.CancelUpdate
Unload Me
frmMDIMain.cmdDocu.Visible = False
frmMDIMain.cmdSheet.Visible = False
frmMDIMain.cmdThermo.Visible = False
frmMDIMain.cmdOther.Visible = False
frmMDIMain.lblCust = ""
frmMDIMain.lblMain.Caption = "Welcome to Print Traxx!"
frmOrderNew.Left = 2925
frmOrderNew.Top = 0
frmOrderNew.Show
End Sub
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
|