Solved

Access VBA Problem

Posted on 2006-11-21
10
682 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

706 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

15 Experts available now in Live!

Get 1:1 Help Now