Hi Fonzie,
Sorry about the errors.. as I said, I made a large number of assumptions when I wrote that post, so it would need to be modified for your use.
Here is the completed code, now that I'm not in a rush.. This code assumes that:
- The inventory table is in the same database as the form
- The inventory table is called "tblInventory"
- The Part Number textbox is called "txtPartNumber"
- The Part Number field in the inventory table is called "Part Number"
- The "Add Part Number to Inventory" form is called "frmInventoryAdd"
--- Begin Code ---
txtPartNumber_BeforeUpdate (Cancel As Integer)
on error goto Err_txtPartNumber_BeforeUpdate
dim dbs as database, rstInventory as recordset
dim strCriteria as string
set dbs=currentdb
set rstInventory = dbs.OpenRecordset ("tblInventory", dbOpenDynaset)
if not isnull (txtPartNumber.value) then
strCriteria = "[Part Number] = " & txtPartNumber.value
rstInventory.findfirst strCriteria
' see if the part number entered is not found
if rstInventory.NoMatch then
if msgbox ("Part number does not exist in " & _
"Inventory Table. Add?",vbYesNo) = vbYes then
docmd.openform "frmInventoryAdd", , , , , _
acDialog, txtPartNumber.Value
end if
end if
Exit_txtPartNumber_BeforeUpdate:
rstInventory.close
set dbs=nothing
Exit Sub
Err_txtPartNumber_BeforeUpdate:
msgbox Err.Number,,"txtPartNumber_BeforeUpdate: " & _
err.Description
resume exit_txtPartNumber_BeforeUpdate
End sub
--- End Code ---
If, after you've made any modifications necessary to use with your database, you're still running into errors with this code, please let me know:
- Whether the program compiled ok (I typed it in this post, not in Access, so it may have some typos)
- If it's a run-time error, what does the error message say
- What is the error number (set to display in the error message caption in run-time errors)
- What line does it seems to be having trouble with
.. and I'll try to figure it out!
