W
wilsonee
Guest
I get error 2471, The object doesn't contain Automation object every time I enter a string into ModelEntry field. If I put a string inside " ", eg. "Cookies" then I don't get the error.
But I get the ProductName record with quotes eg. "Cookies" which I don't want. Why do I have to enter the ProductName inside quotes?
Please help...
Public Sub ModelRecordHandler()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim hldID 'As Double
Dim pkName As String
Dim Inc As Integer
Dim tblName As String
Dim Criteria As String
Set db = CurrentDb()
tblName = "Products"
pkName = "ProductID"
Criteria = "[ProductName] = " & Me![ModelEntry]
'Check if ModelEntry exist in table
hldID = Nz(DLookup("[" & pkName & "]", tblName, Criteria), False)
If hldID Then 'ModelEntry exist
If Me!chkInc Then 'Set Inc via checkboxes for BarEntry exist
Inc = 1
Else
Inc = -1
End If
Else 'ModelEntry does not exist. Add new record
Inc = 1 'Set Inc for new item
'Recordset method is used in order to hold newly assigned
'Primary Key
Set rst = db.OpenRecordset(tblName, dbOpenDynaset)
rst.AddNew
rst!ProductName = Me!ModelEntry
rst!SupplierID = Me!CurrentBrand
rst!InvoiceIDTag = Me!CurrentInvNo
rst!Discount = Forms!frmInvoices!TaxRate
hldID = rst(pkName) 'hold PrimaryKey for lookup later on
MsgBox hldID
rst!ModelNo = hldID
rst.Update
Set rst = Nothing
Me.Requery 'To include new record in form recordsource
End If
Set rst = Me.RecordsetClone
rst.FindFirst pkName & " = " & hldID
Me.Bookmark = rst.Bookmark 'goto record with PrimaryKey = hldID
rst.Edit
Me!InvoiceIDTag = Me!CurrentInvNo
rst.Update
rst.Close
Set rst = Nothing
Me!UnitsInStock = Me!UnitsInStock + Inc 'Increment +/- occurs here
Me!QtyShipped = Me!QtyShipped + Inc 'increment duplicate items
DoCmd.RunCommand acCmdSaveRecord
If Me!UnitsInStock < 0 Then Beep 'Audible warning for less than zero
Me!ModelEntry = "" 'Clear the textbox
Me!chkInc.SetFocus 'Necessary in handling focus!
Me!ModelEntry.SetFocus 'Set focus back for next entry
Set db = Nothing
End Sub
But I get the ProductName record with quotes eg. "Cookies" which I don't want. Why do I have to enter the ProductName inside quotes?
Please help...
Public Sub ModelRecordHandler()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim hldID 'As Double
Dim pkName As String
Dim Inc As Integer
Dim tblName As String
Dim Criteria As String
Set db = CurrentDb()
tblName = "Products"
pkName = "ProductID"
Criteria = "[ProductName] = " & Me![ModelEntry]
'Check if ModelEntry exist in table
hldID = Nz(DLookup("[" & pkName & "]", tblName, Criteria), False)
If hldID Then 'ModelEntry exist
If Me!chkInc Then 'Set Inc via checkboxes for BarEntry exist
Inc = 1
Else
Inc = -1
End If
Else 'ModelEntry does not exist. Add new record
Inc = 1 'Set Inc for new item
'Recordset method is used in order to hold newly assigned
'Primary Key
Set rst = db.OpenRecordset(tblName, dbOpenDynaset)
rst.AddNew
rst!ProductName = Me!ModelEntry
rst!SupplierID = Me!CurrentBrand
rst!InvoiceIDTag = Me!CurrentInvNo
rst!Discount = Forms!frmInvoices!TaxRate
hldID = rst(pkName) 'hold PrimaryKey for lookup later on
MsgBox hldID
rst!ModelNo = hldID
rst.Update
Set rst = Nothing
Me.Requery 'To include new record in form recordsource
End If
Set rst = Me.RecordsetClone
rst.FindFirst pkName & " = " & hldID
Me.Bookmark = rst.Bookmark 'goto record with PrimaryKey = hldID
rst.Edit
Me!InvoiceIDTag = Me!CurrentInvNo
rst.Update
rst.Close
Set rst = Nothing
Me!UnitsInStock = Me!UnitsInStock + Inc 'Increment +/- occurs here
Me!QtyShipped = Me!QtyShipped + Inc 'increment duplicate items
DoCmd.RunCommand acCmdSaveRecord
If Me!UnitsInStock < 0 Then Beep 'Audible warning for less than zero
Me!ModelEntry = "" 'Clear the textbox
Me!chkInc.SetFocus 'Necessary in handling focus!
Me!ModelEntry.SetFocus 'Set focus back for next entry
Set db = Nothing
End Sub