0

Using Access 2010. Fairly new to automation and macros.

I have two tables (tblProductReceived and tblBins) and a form (frmProductReceived).

A field in tblBins corresponds to a location the bin is at (named BinLocationID) and the tblProductReceived table tracks product that a specific bin has received.

What I need is for the tblProductReceived field PRLocationID ([tblProductReceived].[PRLocationID]) to be automatically populated with where the bin is at ([tblBins].[BinLocationID]) when selecting a specific bin in the form (frmProductReceived).

Is there an easy way I can do this? I'm really new at macros/vba and I would extremely be grateful for some tips/suggestions!

Also, there is no object in the form for the PRLocationID field. I want it to be updated behind the scenes based on the bin number field the user selects ([tbl.Bins].[BinID])

Here are images of tblBins, tblProductReceived, and frmProductReceived: http://imgur.com/a/0IUHm/ (can't post images quite yet without reputation)


See this is the structure i have:

tblProductReceived is a table that records items that were deposited into bins.

tblBins is a listing of physical drop locations (bins) that contain a field BinLocationID

BinLocationID actually corresponds to another table (tblLocations) that has all the locations.

But I can't simply link the field from tblBins to tblProductReceived's because sooner or later bins can move from location to location (whatever the reason is is unimportant). This is the reason why I need a copy of [tblBins].[BinLocationID] to be copied over to [tblProductReceived].[PRLocationID] because should a bin move, it would mess any analysis (as we want to keep track of where the product was dropped off at, not only the location of the bin).

Also, the form I set up does have the drop down to the various bins ([PRBinID] in [tblProductReceived] — (i use a lookup query on tblBins) but keep in mind there is no txtBox for the PRLocationID in the field as it's superfluous. The bins are at location already, all i need is for it to be copied over to the appropriate table.

Am i overlooking anything?

4

1 回答 1

0

After picking at it for hours this is the most elegant solution I've come up with:

On the form, I have a hidden txtBox called txtPRLocationID whose row source is PRLocationID (in tblLocations)

After a bin is selected at txtPRBinID, i have an event scripted at Lose Focus:

   'Private Sub txtPRBinID_LostFocus()'
   '[txtPRLocationID].Value = DLookup("[BinLocationID]", "tblBins", "BinID = " & Nz(Me!txtPRBinID.Value, 1))'
   'End Sub'

Basically what it does is everytime a value is selected for txtPRBinID and the user moves on (Loses Focus of the txtBox), a DLookup occurs for tblBins.BinLocationID for the value of BinID and changes the value of txtPRLocationID text box.

The 'Nz()' is to avoid Null errors (according to Google search). Not sure if necessary, if anyone can confirm, please do!

Thanks for reading!

于 2013-09-15T08:03:07.900 回答