Solved

Access VBA Problem

Posted on 2006-11-21
10
712 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
  • 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 49

Expert Comment

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

Set rs = Me.Query2_subform.Form.RecordsetClone

/gustav
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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 200 total points
ID: 17989769
is your search form property popup set to Yes?
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 17989792
Then call DoCmd:

DoCmd.SelectObject acForm, <YourFormName>

/gustav
0
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 300 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

831 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