Results 1 to 4 of 4
  1. #1
    rfhall50 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2009
    Posts
    6

    Help with Selecting a single record in access.

    Please help with my syntax OR SUGGEST A BETTER WAY. I am retrieving a single record from an SQL table. Once retrieved, will display existing values, allow changes, then write the whole record back to the table. Adding and deleting recs works great, but can't get the syntax correct to retrieve the single rec for updating. Have two displays in for diagnostic purposes: one to show the actual sql line, the other trying to display a field for the record I am looking for. My second msgbox always shows blanks or null. Should show a text value.Have no problem with manipulating the form, just can't seem to get the record. Have verifed search criteria. My code is shown below.


    The msgbox for sqlstr shows:
    select * from Asset_Table WHERE ([A_AssetN]) = "11-1-11-00-0001";
    Your help is greatly appreciated !
    Bob
    Code:
     
    Private Sub Command98_Click()
    On Error GoTo Err_Command98_Click
        Dim db As Object
        Dim rst As Object
        Dim sqlstr As String
        Set db = CurrentDb
        sqlstr = "Select * FROM Asset_Table WHERE ([A_AssetN]) = " & Chr$(34) & Me!AI_AssetN & Chr$(34) & ";"
        Set rst = db.OpenRecordset(sqlstr, dbOpenDynaset)
        MsgBox sqlstr
        MsgBox (A_RType)
        Rem DoCmd.RunSQL sqlstr
    Exit_Command98_Click:
        Exit Sub
    Err_Command98_Click:
        MsgBox Err.Description
        Resume Exit_Command98_Click
     
    End Sub

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    I take it A_RType is the field you are trying to display. If so try:
    MsgBox (rst!A_RType)

  3. #3
    rfhall50 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2009
    Posts
    6
    Thank you so much ! It worked great. I never realized I actually had the correct rec. The "rst.", "frm.", etc. are starting to make more sense.

    Again Thank You !

    Bob

  4. #4
    SoftwareMatters is offline Access VBA Developers
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Again Thank You !
    Anytime

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

Similar Threads

  1. Replies: 5
    Last Post: 03-23-2011, 10:39 AM
  2. Replies: 2
    Last Post: 02-10-2009, 12:02 PM
  3. Problem Selecting Records for a Report
    By Joe in forum Programming
    Replies: 0
    Last Post: 09-27-2008, 02:27 PM
  4. Adding a single record
    By kfoyil in forum Forms
    Replies: 2
    Last Post: 11-22-2006, 09:12 PM
  5. Selecting text - ComboBox
    By Numbat in forum Programming
    Replies: 2
    Last Post: 06-05-2006, 05:42 PM

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