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("CompanyName"
<> "" Then
frmWorkorder.txtCompany.Text = datCustomer.Recordset.Fields("CompanyName"
Else
frmWorkorder.txtCompany.Text = ""
End If
frmWorkorder.cboEntered.Text = ""
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
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"
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"
End If
frmWorkorder.datWorkorder.Recordset.AddNew
frmWorkorder.txtCustomerID.Text = datCustomer.Recordset.Fields("CustomerID"
frmWorkorder.txtCustomer.Text = datCustomer.Recordset.Fields("ContactLastName"
frmWorkorder.txtJob.Text = strJob
frmWorkorder.txtRec.Text = Date
If datCustomer.Recordset.Fields("CompanyName"
frmWorkorder.txtCompany.Text = datCustomer.Recordset.Fields("CompanyName"
Else
frmWorkorder.txtCompany.Text = ""
End If
frmWorkorder.cboEntered.Text = ""
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