Results 1 to 3 of 3
  1. #1
    daveystella is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2015
    Posts
    2

    access 2013 vb: 1 not = "1"

    Hi.



    I've got some code that's trying to set the "selected" property in a listbox to highlight the relevant value returned from a recordset. Here's the relevant code.

    [CODE]

    sqlstr = "select * from location where location_name = '" & Me.txt_location_name & "'"
    Set dbname = CurrentDb

    Set loc_data = dbname.OpenRecordset(sqlstr)
    loc_data.MoveFirst

    For Each ctrl In Me.Controls
    If ctrl.ControlType = acListBox Then
    For kount = 0 To ctrl.ListCount - 1
    If ctrl.Name = "lst_location_type" Then
    If ctrl.ItemData(kount) = loc_data.Fields("loc_type") Then
    ctrl.Selected(kount) = True
    Exit For
    End If
    [END CODE]

    The problem I'm getting, is that when I run it, although If ctrl.ItemData(kount) shows up as 1 and loc_data.Fields("loc_type") shows as "1", they're not equal and it drops through.

    I've tried using the Str() function, but no dice.

    Any ideas?

    Cheers.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Try:

    CStr(ctrl.ItemData) = CStr(loc_data.Fields("loc_Type"))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    daveystella is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2015
    Posts
    2
    Yup!

    That did the trick.

    Thanks very much indeed.

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

Similar Threads

  1. Replies: 0
    Last Post: 08-11-2014, 12:25 PM
  2. Replies: 12
    Last Post: 05-23-2013, 10:56 AM
  3. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  4. Replies: 2
    Last Post: 11-04-2011, 02: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