CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Posts
    7

    Access 2003 - Extracting a string value through SQL

    Hi,

    I'm trying to use VBA to extract a string value from a table in a database.

    My effort is below:

    Private Sub Command0_Click()

    Dim SQLString As String
    Dim db As Database
    Dim MachineName As String
    Dim Category As String
    Dim FileName As String

    Stop

    Set db = CurrentDb

    MachineName = "jkl"

    SQLString = "SELECT UserClassification FROM ContactDetails WHERE MachineName = " & MachineName
    Set Category = db.OpenRecordset(SQLString, String)

    'FileName = "UT" & Category

    'DoCmd.OpenReport FileName
    End Sub

    Can anyone tell me what I need to do?

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Access 2003 - Extracting a string value through SQL

    For something like this, I would use ExecuteScalar, rather than returning an entire recordset.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Mar 2007
    Posts
    3

    Re: Access 2003 - Extracting a string value through SQL

    you should use a recordset object to access data:

    Dim CategoryRecordset As Recordset


    Set CategoryRecordset = db.OpenRecordset(SQLString)

    Category=CategoryRecordset![UserClassification]

    ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured