Subform control code refering to main form

R

rpw

Hello everyone,

I need help again. The main form uses a record source where the PK is
FranchiseID. The subform has a record source that includes a field for
invoice numbers [cffcInvoiceNum]. I want the user to enter an invoice number
into a textbox, click the command button and have the main form switch to the
FranchiseID that matches the invoice number's FranchiseID. (I hope that's
clear...)

The Variant is capturing the correct FranchiseID, but the main form is not
moving to that record. I'm not using "Me" in this 'cause I figured with the
code being in a subform "Me" might mean the subform. Here's what I have so
far that's not working:

Dim rs As Object
Dim varFranID As Variant
If Me.txtFindInv <> Null Then
varFranID = DLookup("[FranchiseID]", "tblcffcMatSales",
"[cffcInvoiceNum] = " _
& Forms!frmFranchise!sfrmCffcMatSales.Form!txtFindInv)
Set rs = Forms!frmFranchise.RecordsetClone
rs.FindFirst "[FranchiseID] = " & Str(Nz(varFranID, 0))
If Not rs.EOF Then Forms!frmFranchise.Bookmark = rs.Bookmark
End If

Any help and guidance is appreciated.

tia! :)
 
R

rpw

OK, I've located two errors. One, my "If" statement was wrong. Two, I
didn't need "Str(Nz" etc. surrounding the variant.

Thanks to anyone who posted a reply before I did. And thanks for all past
and future help.

Here's what works:

Dim rs As Object
Dim varFranID As Variant
If Me.txtFindInv > 0 Then
varFranID = DLookup("[FranchiseID]", "tblcffcMatSales", "[cffcInvoiceNum]
= " _
& Forms!frmFranchise!sfrmCffcMatSales.Form!txtFindInv)
Set rs = Forms!frmFranchise.RecordsetClone
rs.FindFirst "[FranchiseID] = " & varFranID
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top