Results 1 to 4 of 4
  1. #1
    kawi6rr is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    39

    ADODB Retrieve Value with SQL Help

    I'm trying to read a value from a table using ADODB below.

    Private Sub Form_Load()
    Dim conn As ADODB.Connection
    Dim strSQL As String
    Set conn = CurrentProject.Connection

    strSQL = "SELECT CFS FROM loadDateCFS"

    conn.Execute strSQL

    Me.txtCFS.value = strSQL

    conn.Close
    Set conn = Nothing

    Me.Dirty = False
    Me.Requery


    End Sub

    When I try to assigne the strSQL value to my txt field the txt field simply displays my select statement.

    txt field shows "SELECT CFS FROM loadDateCFS"

    How can I get it do display the actual date in the tables CFS field?

    Thanks in advance for any help.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you can't use SELECT queries in vba for anything, bud. Not within access, anyway. now, for ado connection to excel sheets, named ranges, and things like that, it serves a different purpose. but what you're trying to do is impossible. use a DLOOKUP() function instead.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    DLookup would work and don't have to bother with the connection and recordset code. But if you really want to use SQL then you need a recordset and set box to the value of field in the query.
    Code:
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
     
    Set conn = CurrentProject.Connection
    Set rs = New ADODB.Recordset
     
    rs.Open "SELECT CFS FROM loadDateCFS;", conn, adOpenStatic, adLockPessimistic
     
    Me.txtCFS = rs!CFS
     
    rs.Close
    That's how I do it. This query will retrieve all records but the textbox is populating with value from the first record.

    The real question is why do you need to do this, what are you really trying to accomplish? Can this field be a part of the form's RecordSource?
    Last edited by June7; 05-05-2011 at 11:44 AM.

  4. #4
    kawi6rr is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    39
    Thanks I'll give it a try!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Retrieve Data Too Slow
    By BGF in forum Programming
    Replies: 8
    Last Post: 09-08-2010, 04:28 PM
  2. Search and Retrieve
    By sadath in forum Access
    Replies: 3
    Last Post: 07-02-2010, 04:54 AM
  3. Replies: 1
    Last Post: 01-23-2010, 01:02 PM
  4. Adodb
    By sassy in forum Programming
    Replies: 2
    Last Post: 10-26-2009, 06:40 PM
  5. Counting large ADODB recordsets
    By harpyopsis in forum Programming
    Replies: 3
    Last Post: 10-16-2009, 10:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums