Trying to open a form using a select string

I have a form which uses a table as it's normal record source.  But I also have a form which contains a combobox.  If the user selects a record from the combo box I want the form to open using that filtered selection as its record source.

Here is my code which is not working.

Private Sub cmdProceed_Click()
On Error GoTo cmdProceed_Click_Err
    
    If Not IsNull(cboSAItaskCardN) Then
    Dim strNewRecord As String
        strNewRecord = "SELECT * FROM tblTaskCardHeader " & " WHERE SAItaskCardN = '" & Me!cboSAItaskCardN.Value & "'"
        Me.RecordSource = strNewRecord
        DoCmd.OpenForm "frmTaskCardHeader", acNormal, , strNewRecord, acFormEdit, acWindowNormal
        Exit Sub
    End If
    
    'Open form with no filters
    DoCmd.OpenForm "frmTaskCardHeader", acNormal, , "[ProjectID]=" & Me.cboProject, acFormEdit, acWindowNormal

cmdProceed_Click_Exit:
    Exit Sub

cmdProceed_Click_Err:
    MsgBox Error$
    Resume cmdProceed_Click_Exit

End Sub

Open in new window

SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
what happen if you replaced line 8

DoCmd.OpenForm "frmTaskCardHeader", acNormal, , strNewRecord, acFormEdit, acWindowNormal

with this

DoCmd.OpenForm "frmTaskCardHeader", acNormal, , "[SAItaskCardN] = '" & Me.cboSAItaskCardN.Value & "'" , acFormEdit, acWindowNormal
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
I get an empty form.  Please note that  SAItaskCardN  is a text field if that matters.
0
Rey Obrero (Capricorn1)Commented:
what is the record source of form "frmTaskCardHeader"?
 is it the table "tblTaskCardHeader" ?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SteveL13Author Commented:
Yes.
0
Rey Obrero (Capricorn1)Commented:
so, if the form opens empty, there is no SAItaskCardN equal to the value of  combo cboSAItaskCardN.

what is the row source of combo "cboSAItaskCardN" ?
0
SteveL13Author Commented:
This worked...

DoCmd.OpenForm "frmTaskCardHeader", acNormal, , "[SAItaskCardN] = '" & Me.cboSAItaskCardN.Value & "'" , acFormEdit, acWindowNormal

But I had extra code at the end of that line when I copy/pasted it in.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.