Solved

ADO If .find record then display the fields

Posted on 2008-09-30
7
760 Views
Last Modified: 2013-11-28
In DAO code the following code finds the record and displays the fields selected on the form..
I have ADO code that I think is almost working but it doesn't fill out the fields like I expect.
With ADO do I need to set each field to a value or is there DAO equivalent code that populates the fields on the form.
Thanks
ADO Code - See attached.
DAO Code
    Set db = CurrentDb()
    Set rs = Me.RecordsetClone
    rs.FindFirst "[WorkReleaseId] = " & cboReleaseNo.Value
        If rs1.NoMatch Then
            MsgBox "Not Found"
        Else
            Me.Bookmark = rs1.Bookmark
        End If
   'rs.Close
ADO

Set cn = New ADODB.Connection

Set rs1 = New ADODB.Recordset

cn.Open "Provider=SQLNCLI;Server=10.0.0.10\SQLExpress;Database=FDThomasQC;Trusted_Connection=yes;"

rs1.Open "SELECT WorkReleaseID FROM tblWorkRelease WHERE WorkReleaseID = " & cboReleaseNo, cn, adOpenKeyset

    rs1.MoveFirst

    rs1.Find "[WorkReleaseId] = " & cboReleaseNo.Value

        If rs1.EOF Then

            MsgBox "Not Found"

        Else

            'HOW DO I POPULATE FORM FIELDS HERE?

        End If

Open in new window

0
Comment
Question by:BobRosas
  • 4
  • 3
7 Comments
 
LVL 84
ID: 22610338
Set cn = New ADODB.Connection
Set rs1 = New ADODB.Recordset

cn.Open "Provider=SQLNCLI;Server=10.0.0.10\SQLExpress;Database=FDThomasQC;Trusted_Connection=yes;"

rs1.Open "SELECT WorkReleaseID FROM tblWorkRelease WHERE WorkReleaseID = " & cboReleaseNo, cn, adOpenKeyset

If Not (rs1.EOF and rs1.BOF) then
  '/you found a record
Else
  '/you did NOT find a record
End IF
0
 
LVL 84
ID: 22610346
I think I misunderstood, although the "search" I show is more efficient than yours.

You cannot set a bookmark in the same manner as you're doing with DAO. Are you using a bound form? If you are, then you can set the .Recordset value of your form to your rs! variable, if you set the CursorLocation to adUseClient.

0
 

Author Comment

by:BobRosas
ID: 22610416
Thank you for your quick response.  
How to fill the form if I find something is what I'd like to know more about.  Could you be more specific using code on how I set the recordset value?

If Not (rs1.EOF and rs1.BOF) then
  Set rs1 = Me.Recordset  'GET TYPE MISMATCH ERROR
Else
  '/you did NOT find a record
End IF

0
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

 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 22610542
You've got it backwards:

Set Me.Recordset = rs1

However, you must use the Clientside cursor ... before you open your recordset do this:

rs1.CursorLocation = adUseClient
0
 

Author Comment

by:BobRosas
ID: 22610622
Obviously I still don't have something right because I get the message ...
                Operation is not allowed when the object is open.
but here's what I have.
Thanks again.

       If Not (rs1.EOF And rs1.BOF) Then
            rs1.CursorLocation = adUseClient
            Set Me.Recordset = rs1
        Else
            '/you did NOT find a record
        End If
0
 
LVL 84
ID: 22612672
As I wrote earlier, you must set the CursorLocation BEFORE you open the Recordset ... not in the If block.
0
 

Author Closing Comment

by:BobRosas
ID: 31501789
You were a huge help so I increased points.
Thanks again!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
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…

762 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

19 Experts available now in Live!

Get 1:1 Help Now