By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,100 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,100 IT Pros & Developers. It's quick & easy.

creating an inventory application

P: n/a
Let me start by saying that I'm a newbie in VBA.

I've created an application in access where the user enters the quantity of
the items sold in a form. I would like to have these records created in a
table, mentioning the qty sold, the transaction date etc. this table I'm
planning to use afterward to calculate the quantity on hand.

I have created the following code, but I keep on receiving the error, that
it does not recognize the fields mentioned in the code.

Private Sub Form_AfterUpdate()
Dim rst As DAO.Recordset
Dim mdbLocal As DAO.Database
Set mdbLocal = DBEngine(0)(0)
Set rst = mdbLocal.OpenRecordset("visits", dbOpenDynaset, dbAppendOnly)

If Me![Owndepomys] = False Then
[Inventory.Storeroom] = "FP02"
[Inventory.TransactionDate] = Me![Datevisit]
[Inventory.Artcode] = DLookup("[ArtCode]", "Contraceptives", "
[Description]=" & Forms![visits]!Description)
[Inventory.Description] = Me![Contraceptives]
[Inventory.TransactionDescription] = "Over the counter"
[Inventory.UnitsSold] = Me![Qty]
[Inventory.Qtyonhand] = [Inventory.Qtyonhand] - Me![Qty]
[Inventory.AmountQty] = [Inventory.AmountQty] * Me!

End If

End Sub

Message posted via
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
you need to prefix the field names with the name of the recordset...

If Not Me![MyBoolean] Then
'--Set the values for individual fields
rst.Fields("Inventory Storeroom")="FP02"
'--Save the record
End If

Nov 13 '05 #2

P: n/a
Thanks for your reaction, I've changed my code as per your suggestion and I
still get the same error code 2465, "can't find field "|" referred to in
your expression."

This is the changed code. Could you have a look at it again? Thanks again
for your help.

Private Sub Form_AfterUpdate()
'If Me.NewRecord Then

Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Transaction Table", dbOpenTable)

If Not Me![Owndepomys] Then
rst.Fields([Transaction Table].[Storeroom]) = "FP02"
[Transaction Table.TransactionDate] = Me![Datevisit]
[Transaction Table.Artcode] = DLookup ("[ArtCode]",
"Contraceptives", "[Description]=" & Forms![visits]!Description)
[Transaction Table.TransactionDescription] = "Over the counter"
[Transaction Table.UnitsSold] = Me![Qty]
[Transaction Table.AmountQty] = [Transaction Table.AmountQty] * Me!

End If
'End If

Exit Sub
End Sub

Message posted via
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.