Link to home
Create AccountLog in
Avatar of wlwebb
wlwebbFlag for United States of America

asked on

Access - Click on record on Subform to Select Main Form Item

Hello All

I have a Form with one subform.  That subform is a continuous form where I list all Inventory Items in the system.  My main form is to input or edit an individual Inventory Item.

 (I didn't use a Listbox because I don't like the fact that I can't align individual list columns left, right or center - maybe you can and I just don't see a place to instruct it how to align)

So, on my Subform I have the primary key field [InvItemID] not visible.  They can see the [InvItem] description along with some other fields. In the [InvItem] OnClick event I want it to select the main form's selected Inv Item.

I tried using
Private Sub InvItem_Click()
    DoCmd.SearchForRecord , "frm_InvItem", acFirst, "[InvItem] = " & Str(Nz(Screen.ActiveControl, 0))
End Sub

However I get a Type Mismatch.
Avatar of als315
als315
Flag of Russian Federation image

Can you upload sample DB with your form and some dummy data?
I don't see how this bit is reliable.

"[InvItem] = " & Str(Nz(Screen.ActiveControl, 0))

From what you say the user could be clicking on any of several fields and surely the InvItem field in the main form has to match  the one  corresponding field in the subform, not just any field.

But I think you would need...
"[InvItem] = '" & Str(Nz(Screen.ActiveControl, 0)) & "'"
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of wlwebb

ASKER

LSM thanks..

Peter.. I still got the Type Mismatch message