Hello,
I am having difficulty with Access VBA code. I am using Access 2010 (from work)/2013 (from home). I am creating a database that analyzes the nutritional quality of prepackaged foods for my place of employment, a local food bank.
Users enter a products UPC Code (which I use as the Primary Key). What I would like it to do, is if the product has been previously entered, the Product Form will open. If it is not yet in the database, I would like it to go to a new form with the UPC Code, which was previously entered to search, already populated.
I am able to get these to work individually, but as soon as I try to place them together, it fails. I have included the code that has worked below.
The following code opens a matching record to the appropriate form.
Then this code opens a new form with the UPC Code populated.
This is my first post here, so I apologize if I am missing anything, information or posting process. Please feel free to ask any questions or leave any comments. Any help on this would be amazing.
Thank you.
L
I am having difficulty with Access VBA code. I am using Access 2010 (from work)/2013 (from home). I am creating a database that analyzes the nutritional quality of prepackaged foods for my place of employment, a local food bank.
Users enter a products UPC Code (which I use as the Primary Key). What I would like it to do, is if the product has been previously entered, the Product Form will open. If it is not yet in the database, I would like it to go to a new form with the UPC Code, which was previously entered to search, already populated.
I am able to get these to work individually, but as soon as I try to place them together, it fails. I have included the code that has worked below.
The following code opens a matching record to the appropriate form.
Code:
Private Sub cmdOK_Click() DoCmd.OpenForm "frmProduct", acNormal, "", "[UPCCode]=[Forms]![frmUPCCodeSearch]![txtUPCCodeSearch]", acReadOnly, acNormal DoCmd.Close acForm, "frmUPCCodeSearch" End Sub
Code:
Private Sub cmdSearchOpenForm_Click() DoCmd.OpenForm "frmProduct", acNormal, acFormAdd, acWindowNormal Forms!frmProduct!UPCCode = Me.txtUPCSearch DoCmd.Close acForm, "frmUPCSearch" End Sub
Thank you.
L
Comment