Results 1 to 2 of 2
  1. #1
    forums1167 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Jun 2013
    Posts
    1

    combo box, selection, sql

    I am creating a combo box with a button. In the below vba code, I am getting the string from the combo box. Then, I am trying to use SQL to the corresponding distro lists in the table (same row). This VBA code below is getting a Run-time error '438' Object doesn't support this property or method and it points to the SQL statment in the debugging screen. Any help is greatly appreciated.




    Code:
    Private Sub Command11_Click()
    Dim cnn As ADODB.Connection
      Dim rs As ADODB.Recordset
      Dim SQL As String
      Dim vFld As Variant
     
    string1 = Combo27.Value
     
    SQL = "SELECT [" & DistributionLists & "]  as Fld" & _
    " FROM " & DistroLists & " WHERE " & string1 & "=" & Application
     
     
      rs.Open SQL
     
      vFld = rs!Fld
     
      Set cnn = Nothing
      Set rs = Nothing
     
     
     
    MsgBox (vFld)
     
     
    End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    throw in a debug.print sql the SQL generation line and see what it's giving you, cut and paste that code to the SQL window of a query in Access and see what happens, you'll likely get a better (more usable) error message than in your vb code.

    Code:
    SQL = "SELECT [" & DistributionLists & "]  as Fld  FROM " & DistroLists & " WHERE " & string1 & "=" & Application
    debug.print sql
    I suspect it's something to do with your 'Application' unless that's a field on your form, application may be a reserved word and that's why you may be having trouble with it. Try changing your field name to fldApplication and your SQL statement to

    Code:
    SQL = "SELECT [" & DistributionLists & "]  as Fld  FROM " & DistroLists & " WHERE " & string1 & "=" & fldApplication

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

Similar Threads

  1. Replies: 3
    Last Post: 12-11-2012, 09:12 AM
  2. Replies: 1
    Last Post: 10-30-2012, 10:29 AM
  3. Replies: 1
    Last Post: 07-11-2012, 08:36 AM
  4. Replies: 33
    Last Post: 01-13-2012, 07:44 AM
  5. Replies: 1
    Last Post: 08-26-2009, 10:45 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