Results 1 to 4 of 4
  1. #1
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36

    referencing a control

    Can anyone tell me what is wrong with this?

    Run time error '2185'
    You can't reference a property or method for a control unless the control has the focus.


    Private Sub AssignButton_Click()
    Dim SQLMasterUpdate As String
    Dim oItem As Variant

    If Me!RestaurantListBox.ItemsSelected.Count <> 0 Then
    For Each oItem In Me!RestaurantListBox.ItemsSelected
    SQLMasterUpdate = "UPDATE Restaurant SET " & _
    "Restaurant.AccountManagerID = (SELECT AccountManagerID FROM AccountManager " & _
    "WHERE AccountManagerName = " & Me!AccountManagerName.Text & ") " & _
    "WHERE ((SELECT RestaurantInfo, RestaurantPhone FROM Restaurant) = " & oItem & ");"
    DoCmd.RunSQL SQLMasterUpdate
    Next oItem
    Else
    MsgBox "Nothing was selected from the list", vbInformation
    Exit Sub 'Nothing was selected
    End If
    End Sub

  2. #2
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    Oh, I figured it out. I changed .Text to .Value.

    The subquery still doesn't work but that's a whole 'nother issue.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    For testing and debugging use a
    debug.print SQLMasterUpdate

    and comment out 'DoCmd.RunSQL SQLMasterUpdate
    while doing this test.
    You will see what the SQL looks like and can check it for errors (visually).

    I think you're missing some quotes(') that would surround a text value in the Update statement.

  4. #4
    looloo is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    36
    thanks, orange. That's a good tip.

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

Similar Threads

  1. Referencing Issue
    By rosh41 in forum Forms
    Replies: 1
    Last Post: 07-15-2010, 04:09 AM
  2. Referencing a Subroutine
    By Lockrin in forum Programming
    Replies: 1
    Last Post: 02-26-2010, 10:09 AM
  3. Replies: 0
    Last Post: 12-08-2009, 01:19 PM
  4. Replies: 0
    Last Post: 01-28-2009, 03:47 AM
  5. referencing each record
    By grgerhard in forum Forms
    Replies: 1
    Last Post: 11-11-2006, 08:15 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