Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ADO If .find record then display the fields

Posted on 2008-09-30
7
Medium Priority
?
770 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 85
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 85
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 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 85
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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