Results 1 to 3 of 3
  1. #1
    John2810 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    2

    What is wrong with my SQL Select statement?

    Hey guys,

    I keep getting into a "invalid operation" problem with the following code, but I can't see what's wrong!!

    The part of the code that is highlighted is highlighted in bold.

    I'm stuck at this for over 3 hours now...please advise!

    Code:
    Private Sub cmdMatchFields_Click()
    Dim db As Database, rs As DAO.Recordset
    Dim tbl As DAO.TableDef
    Dim fld As DAO.Field
    Dim strSQL As String
    
    MsgBox "test"
    
    Set db = CurrentDb
    Set tbl = db.TableDefs("tbl" & strSupplier & "temp")
    
    For Each fld In tbl.Fields
    strSQL = "SELECT [FieldName] FROM tblFieldDefinition INNER JOIN tblFieldThesaurus ON " & _
            "tblFieldDefinition.ID = tblFieldThesaurus.ID " & _
            "WHERE FieldNameAlt = '" & fld & "'"
    Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
    If rs.EOF Then
    MsgBox "No match found for" & fld
    Else
    db.TableDefs("tbl" & strSupplier & "temp").Fields(1).Name = rs!FieldName
    End If
    Next fld
    
    Set fld = Nothing
    Set tbl = Nothing
    Set rs = Nothing
    Set db = Nothing
    End Sub


  2. #2
    John2810 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    2
    Just managed to solve it...

    There's nothing wrong with my SQL statement...my fld was stated correctly, Access doesn't know what I want to change.

  3. #3
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    Mark the thread as solved please.

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

Similar Threads

  1. Use of COLLATE statement in SELECT clause
    By zurek in forum Queries
    Replies: 7
    Last Post: 03-16-2011, 06:46 AM
  2. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM
  3. What's wrong with this expression
    By tallroger in forum Access
    Replies: 1
    Last Post: 05-05-2009, 04:00 PM
  4. Compiler WRONG example-DB
    By pacala_ba in forum Access
    Replies: 12
    Last Post: 04-18-2009, 01:00 PM
  5. What am I doing wrong?
    By brandon in forum Access
    Replies: 2
    Last Post: 08-03-2008, 10:26 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