I have a Master Detail form linked to access tables, which I used the form wizard to make. I havent been using visual basic for very long so I am unsure where I am going wrong. I am having lots of problems with the form.
The form has text fields for the master, and a datagrid to display the detail, and add, delete,refresh & edit buttons.
When I try to add a record the datagrid will only let me add the master details and one row into the datagrid. I tried using various keys to go to the next line but it will not work. If I then update the record I have to refresh it before I can add anymore data to the datagrid, and once its been refreshed I can add as many details as I like.
Then when I go to delete a record it will not work I get the error 'record cannot be deleted or changed because table table cust_ord_line includes related records'.
If I delete the datagrid contents using the delete button on the keyboard, and then try to refresh or delete the master data I get the message 'row handle referred to a deleted row or a row marked for deletion'. Can anyone suggest a way I can fix my code to update or delete the whole record correctly. The code for the update and delete buttons is below. This is extremely urgent and I could not find any other postings about this in the forum. Thanks in advance.
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
' if required fields not empty update record
If txtFields(0) = "" Or txtFields(1) = "" Or txtFields(3) = "" Or txtFields(4) = "" Then
MsgBox "You have not filled in one of the required fields, please try again!", , "Error"
Else
adoPrimaryRS.UpdateBatch adAffectAll
If mbAddNewFlag Then
adoPrimaryRS.MoveLast 'move to the new record
End If
mbEditFlag = False
mbAddNewFlag = False
SetButtons True
mbDataChanged = False
End If
'refresh recordset
Exit Sub
UpdateErr:
cmdCancel.Enabled = False 'disable cancel until adjusted
MsgBox "Some information you entered is incorrect, please adjust it or consult manual and try again!", , "Error"
End Sub
Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, " Continue?"
= vbYes Then
'delete current record
With adoPrimaryRS
If adoPrimaryRS.EOF = False And adoPrimaryRS.BOF = False Then
.Delete
Set grdDataGrid.DataSource = Nothing
adoPrimaryRS.Requery
Set grdDataGrid.DataSource = adoPrimaryRS("ChildCMD"
.UnderlyingValue
.MoveNext
Exit Sub
Else
MsgBox "There are no records to delete!", , "Attention!"
End If
End With
End If
Exit Sub
DeleteErr:
MsgBox "To delete a customer order you must first go to edit and delete order contents, please consult manual", , "Error"
The form has text fields for the master, and a datagrid to display the detail, and add, delete,refresh & edit buttons.
When I try to add a record the datagrid will only let me add the master details and one row into the datagrid. I tried using various keys to go to the next line but it will not work. If I then update the record I have to refresh it before I can add anymore data to the datagrid, and once its been refreshed I can add as many details as I like.
Then when I go to delete a record it will not work I get the error 'record cannot be deleted or changed because table table cust_ord_line includes related records'.
If I delete the datagrid contents using the delete button on the keyboard, and then try to refresh or delete the master data I get the message 'row handle referred to a deleted row or a row marked for deletion'. Can anyone suggest a way I can fix my code to update or delete the whole record correctly. The code for the update and delete buttons is below. This is extremely urgent and I could not find any other postings about this in the forum. Thanks in advance.
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
' if required fields not empty update record
If txtFields(0) = "" Or txtFields(1) = "" Or txtFields(3) = "" Or txtFields(4) = "" Then
MsgBox "You have not filled in one of the required fields, please try again!", , "Error"
Else
adoPrimaryRS.UpdateBatch adAffectAll
If mbAddNewFlag Then
adoPrimaryRS.MoveLast 'move to the new record
End If
mbEditFlag = False
mbAddNewFlag = False
SetButtons True
mbDataChanged = False
End If
'refresh recordset
Exit Sub
UpdateErr:
cmdCancel.Enabled = False 'disable cancel until adjusted
MsgBox "Some information you entered is incorrect, please adjust it or consult manual and try again!", , "Error"
End Sub
Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, " Continue?"
'delete current record
With adoPrimaryRS
If adoPrimaryRS.EOF = False And adoPrimaryRS.BOF = False Then
.Delete
Set grdDataGrid.DataSource = Nothing
adoPrimaryRS.Requery
Set grdDataGrid.DataSource = adoPrimaryRS("ChildCMD"
.MoveNext
Exit Sub
Else
MsgBox "There are no records to delete!", , "Attention!"
End If
End With
End If
Exit Sub
DeleteErr:
MsgBox "To delete a customer order you must first go to edit and delete order contents, please consult manual", , "Error"