Solved

Access VBA Problem

Posted on 2006-11-21
10
698 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
 
LVL 119

Expert Comment

by:Rey Obrero
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 119

Accepted Solution

by:
Rey Obrero 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now