J
Johnkl via AccessMonster.com
Hi all
Can you please read the code below and tell me what I'm doing wrong??? I can
not make it work no matter what..
All I'm trying to do is transfer the data to two other tables and then change
the status of the line from pending(0) to ordered (1)
Please help.............................
Kind regards
John
Private Sub cmdSales_Click()
On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim db As Database
Dim rs As DAO.Recordset
Dim strSql As String 'SQL statement.
Dim strMsg As String
Dim lngID As Long 'Primary key value of the new record.
Dim frm As Form
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select or Insert Proposal to Post to Sales.", vbCritical,
gstrAppTitle
Else
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblSales")
With Me.RecordsetClone
rs.AddNew
rs![OrderDate] = [ArrivalDate]
rs![EmployeeID] = [EmployeeID]
rs![File] = [FileID]
rs![CustomerID] = [CustomerID]
rs![QuoteID] = [QuoteID]
'Save and edits first
rs.Update
rs.Bookmark = rs.LastModified
lngID = rs!SaleID
If Me.[frmQuoteDetailsSubform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [tblSales_Details] ( SaleID, Service, Price,
SupplierID, QuoteDetailID ) " & _
"SELECT " & lngID & " As SaleID, ServiceID, SupplierID,
SellPerItem, QuoteDetailID " & _
"FROM [tblQuoteDetails] WHERE (Quoted=True) AND (Status=0)
"
DBEngine(0)(0).Execute strSql, dbFailOnError
MsgBox "Succesfully Added Sales to This File!", vbInformation,
gstrAppTitle
THIS IS WHERE I HAVE THE PROBLEM Set rs = db.OpenRecordset
("tblQuoteDetails")
DBEngine(0)(0).Execute "UPDATE tblQuoteDetails SET Status=1 WHERE
QuoteDetailID = " & Me.frmQuoteDetailsSubform.Form.QuoteDetailID,
dbFailOnError ("This is where I Have a problem and I can not make it work -
ERROR 91-OBJECVT VARIABLE OR WITH NOT SET)
Set rs = Nothing
rs.Close
End If
End With
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdSales_Click"
Resume Exit_Handler
End If
'End If
'End If
End Sub
Can you please read the code below and tell me what I'm doing wrong??? I can
not make it work no matter what..
All I'm trying to do is transfer the data to two other tables and then change
the status of the line from pending(0) to ordered (1)
Please help.............................
Kind regards
John
Private Sub cmdSales_Click()
On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim db As Database
Dim rs As DAO.Recordset
Dim strSql As String 'SQL statement.
Dim strMsg As String
Dim lngID As Long 'Primary key value of the new record.
Dim frm As Form
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select or Insert Proposal to Post to Sales.", vbCritical,
gstrAppTitle
Else
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblSales")
With Me.RecordsetClone
rs.AddNew
rs![OrderDate] = [ArrivalDate]
rs![EmployeeID] = [EmployeeID]
rs![File] = [FileID]
rs![CustomerID] = [CustomerID]
rs![QuoteID] = [QuoteID]
'Save and edits first
rs.Update
rs.Bookmark = rs.LastModified
lngID = rs!SaleID
If Me.[frmQuoteDetailsSubform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [tblSales_Details] ( SaleID, Service, Price,
SupplierID, QuoteDetailID ) " & _
"SELECT " & lngID & " As SaleID, ServiceID, SupplierID,
SellPerItem, QuoteDetailID " & _
"FROM [tblQuoteDetails] WHERE (Quoted=True) AND (Status=0)
"
DBEngine(0)(0).Execute strSql, dbFailOnError
MsgBox "Succesfully Added Sales to This File!", vbInformation,
gstrAppTitle
THIS IS WHERE I HAVE THE PROBLEM Set rs = db.OpenRecordset
("tblQuoteDetails")
DBEngine(0)(0).Execute "UPDATE tblQuoteDetails SET Status=1 WHERE
QuoteDetailID = " & Me.frmQuoteDetailsSubform.Form.QuoteDetailID,
dbFailOnError ("This is where I Have a problem and I can not make it work -
ERROR 91-OBJECVT VARIABLE OR WITH NOT SET)
Set rs = Nothing
rs.Close
End If
End With
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdSales_Click"
Resume Exit_Handler
End If
'End If
'End If
End Sub