Open record from combobox (1 Viewer)

helmerr

Registered User.
Local time
Today, 11:49
Joined
Nov 27, 2013
Messages
140
I have a form "frmRequisitions" with unbound controls which is used for data entry.

I've placed a combobox in the form header which I would like to use to filter previously saved records from the "Description" record field, then open that previously saved record on the existing (opened) form.

How might I go about doing this? I've placed the following code in the combo box's After Update event. The form appears to refresh, but it doesn't bring up the selected record based on the Description field.


Code:
DoCmd.OpenForm FormName:="frmRequisitions", WhereCondition:="[Description]=" & Chr(34) & Me.cboBrowse & Chr(34)
 

isladogs

CID Moderator
Staff member
Local time
Today, 16:49
Joined
Jan 14, 2017
Messages
13,421
Description is a text field so needs text delimiters.
Use one of these

Code:
DoCmd.OpenForm "frmRequisitions",,,"Description='" & Me.cboBrowse & "'"
Or
Code:
DoCmd.OpenForm FormName:="frmRequisitions", WhereCondition:="[Description]='" & Me.cboBrowse & "'"
 

helmerr

Registered User.
Local time
Today, 11:49
Joined
Nov 27, 2013
Messages
140
Thanks for your help. I tried both your codes but I'm unfortunately receiving the same results. It's a fairly simple database; I'm uploading it here if you have a chance to review the combobox/form.
 

Attachments

isladogs

CID Moderator
Staff member
Local time
Today, 16:49
Joined
Jan 14, 2017
Messages
13,421
Whilst I'm sure I could fix it for you, there's a much better solution.
Unbound forms are almost always a bad idea.
You make unnecessary work for yourself having to write code that Access does automatically in bound forms

So change all your textbox controls from unbound to bound.
You can then get rid of almost all of your code and the form will filter correctly.
To add new records, you would then either open the form in data entry mode or click on New record button or use the navigation buttons at the top
 

helmerr

Registered User.
Local time
Today, 11:49
Joined
Nov 27, 2013
Messages
140
Lol - thanks, that fixed it. I originally took the unbound route because the last database I had to make was quite big and complicated.
 

isladogs

CID Moderator
Staff member
Local time
Today, 16:49
Joined
Jan 14, 2017
Messages
13,421
Glad you solved it.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom