Solved

ADO If .find record then display the fields

Posted on 2008-09-30
7
765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

751 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