Solved

ADO If .find record then display the fields

Posted on 2008-09-30
7
762 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
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.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 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

23 Experts available now in Live!

Get 1:1 Help Now