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

    Exit Sub

    MsgBox Error$
    Resume cmdProceed_Click_Exit

End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

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.
Rey Obrero (Capricorn1)Commented:
what is the record source of form "frmTaskCardHeader"?
 is it the table "tblTaskCardHeader" ?
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

SteveL13Author Commented:
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" ?
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.
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.