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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Runtime Error 3426

Status
Not open for further replies.

dargus

MIS
Feb 6, 2003
3
US
I'm trying to add a new record to a table but every time the recordset trys to update I get VB Runtime error 3426 The action was canceled by an assoiated object. I somewhat understand what this error means and why I am seeing it but I can't figure out a way to correct it. What I am trying to do in this particual part of the program is to create a workorder for a customer. The customer form is open with all the customer information then when I click create workorder the workorder form opens and a new record is added that is matched to the current customer.

Here is the code that gives the error:
Private Sub cmdWorkorder_Click()
Dim rstBoD As New ADODB.Recordset, rstJob As New ADODB.Recordset, rstWrite As New ADODB.Recordset
Dim intPos As Integer
Dim strJob As String, strDate As String, strDay As String, strMonth As String, strYear As String


frmWorkorder.Visible = True
frmCustomer.Visible = False

rstBoD.Open "SELECT * FROM Settings", setDbInit.getConnection

If True Then 'rstBoD.Fields("BoD") = True Then
strDate = Date

intPos = InStr(strDate, "/")
strMonth = Left(strDate, intPos - 1)

If Len(strMonth) = 1 Then
strMonth = "0" & strMonth
End If


strDate = Right(strDate, Len(strDate) - intPos)

intPos = InStr(strDate, "/")
strDay = strJob & Left(strDate, intPos - 1)
'MsgBox strMonth

strDate = Right(strDate, Len(strDate) - intPos)


If Len(strDay) = 1 Then
strDay = "0" & strDay
End If

strYear = strDate
strJob = "J" & strMonth & strDay & strYear & "-1"
Else
rstJob.Open "SELECT * FROM Workorders ORDER BY JobNumYear, JobNumMonth, JobNumDay, JobNumDaily", dbInit.getConnection, adOpenDynamic
rstJob.MoveLast
strJob = "J" & rstJob.Fields("JobNumMonth") & rstJob.Fields("JobNumDay") & rstJob.Fields("JobNumYear") & "-" & (rstJob.Fields("JobNumDaily") + 1)
End If

frmWorkorder.datWorkorder.Recordset.AddNew
frmWorkorder.txtCustomerID.Text = datCustomer.Recordset.Fields("CustomerID")
frmWorkorder.txtCustomer.Text = datCustomer.Recordset.Fields("ContactLastName") & ", " & datCustomer.Recordset.Fields("ContactFirstName")
frmWorkorder.txtJob.Text = strJob
frmWorkorder.txtRec.Text = Date

If datCustomer.Recordset.Fields(&quot;CompanyName&quot;) <> &quot;&quot; Then
frmWorkorder.txtCompany.Text = datCustomer.Recordset.Fields(&quot;CompanyName&quot;)
Else
frmWorkorder.txtCompany.Text = &quot;&quot;
End If
frmWorkorder.cboEntered.Text = &quot;&quot;

End Sub


After this opens the workorder form no updates can be performed on its recordset. Can anyone suggest a better way of doing this or at least one that works?
-Robin
 
after a quick search on the net i found this :

Extract from MSDN Library

PRB This Action was Cancelled by an Associated Object.(3426)&quot;
ID: Q189851


SYMPTOMS
This article discusses the error message &quot;This action was cancelled by an associated object.&quot; that Visual Basic generates when working with Access databases and the Data control. This article does not apply to the ADO data control.


CAUSE
This error is being generated because the AddNew command of a bound recordset causes Visual Basic to try to save the current record if the data has changed. Because the data control is currently pointing to a NULL record and not an empty record, the data cannot be saved so the &quot;action was cancelled by an associated object&quot; error is reported. This is commonly seen when using the data form wizard in Visual Basic versions 4.0 and 5.0. The data form wizard in Visual Basic 6.0 generates code for the ADO data control so this error is less likely to occur.


RESOLUTION
Check the underlying recordset to see if either the BOF or EOF properties are True before allowing an implicit save to occur. An implicit save occurs either when using the data control to navigate off of a record where the information has changed or adding a record to a bound recordset.

 
I've seen that document before and it is of little help. When I get the error neither BOF nor EOF is true. Even if one of them were true skipping the update procedure would be unacceptable anyway. I need a suggestion that allows me to update record or else I'll lose data. The problem seems to be procedural in nature. I'm either doing something I shouldn't or not doing something I should. I also just discovered that if I comment out all the stuff that writes data from the customer form to the workorder form (from the line after the add new up to the end sub) that the update will run without the error. Should I pass the data to the workorder form and change the text box values from there?
 
I tried moving the code that writes to the workorder form onto the workorder form and it works fine. Programming can be really annoying sometimes :)
 
Generally Speaking, when i've tried using bound controls in the past, ive always had to go back and rewrite using nonbound methods. Nowadays i dont use bound controls because i think they are a waste of time.

>>> Programming can be really annoying sometimes
Programming is what keeps me alive, visual basic can sometimes be annoying

Rich.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top