Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access VBA Problem

Posted on 2006-11-21
10
Medium Priority
?
797 Views
Last Modified: 2012-05-05
Experts - I am getting a Run-Time Error '7951':
              You entered an expression that has an invalid reference to the RecordsetClone property.

*The arrow indicates the line that is highlighted:

    [Form_Query2 subform].Visible = True

Dim sWhere As String
Dim sSql As String

sSql = "SELECT tblCompany.PolicyHolderName, tblEOI_Import.* FROM tblCompany LEFT JOIN tblEOI_Import ON tblCompany.[ControlNumber] = tblEOI_Import.Control"
sWhere = " WHERE "

If Not IsNull(Me.txtBadge) Then
    sSql = sSql & sWhere & " tblEOI_Import.EE_BadgeID Like '" & Me.txtBadge & "'"
    sWhere = " AND "
End If

If Not IsNull(Me.txtMember_SSN) Then
    sSql = sSql & sWhere & "tblEOI_Import.EE_SSN Like '" & Me.txtMember_SSN & "'"
    sWhere = " AND "
End If

If Not IsNull(Me.txtLastNameSearch) Then
    sSql = sSql & sWhere & "tblEOI_Import.EE_LastName Like '" & Me.txtLastNameSearch & "'"
    sWhere = " AND "
End If

[Form_Query2 subform].RecordSource = sSql

Dim rs As DAO.Recordset
----->Set rs = Me.Query2_subform.Form.Recordset<-----
'rs.MoveLast
If rs.RecordCount = 0 Then
    [Form_Query2 subform].Visible = False
     LblNoRecs.Visible = True
Else
    [Form_Query2 subform].Visible = True
    LblNoRecs.Visible = False
End If


End Sub
0
Comment
Question by:Sariff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 8

Expert Comment

by:Pigster14
ID: 17989648
If SSql is the same as the recordsource, try replacing that line with the following:


Set rs = currentdb.OpenRecordset(ssql)
0
 
LVL 8

Expert Comment

by:Pigster14
ID: 17989662
It may not like you calling the recordsource of a form as a recordset.

Thanks.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 17989671
I guess it should read:

Set rs = Me.Query2_subform.Form.RecordsetClone

/gustav
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 17989672
or you can do this

Set rs = Me.Query2_subform.Form.RecordsetClone
0
 

Author Comment

by:Sariff
ID: 17989734
that fixed the RunTime error...but now the Subform opens behind the Search form!! Instead of in the subform!

-Sariff
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 800 total points
ID: 17989769
is your search form property popup set to Yes?
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 17989792
Then call DoCmd:

DoCmd.SelectObject acForm, <YourFormName>

/gustav
0
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 1200 total points
ID: 17989877
[Form_Query2 subform].RecordSource = sSql  - here you call it [Form_Query2 subform]

Shouldn't it be:
Me![Form_Query2 subform].Form.RecordSource = sSql

Dim rs As DAO.Recordset
----->Set rs = Me.Query2_subform.Form.Recordset<----- here you call it Query2_subform  

Are they both the same subfrom?
0
 

Author Comment

by:Sariff
ID: 17989922
Thanks to all!!

-Sariff
0
 
LVL 44

Expert Comment

by:GRayL
ID: 17989968
Thanks, glad to help.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question