Results 1 to 6 of 6

Thread: [RESOLVED] [Access 2003] Form ComboBox Blank Item problem

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Resolved [RESOLVED] [Access 2003] Form ComboBox Blank Item problem

    I have a form in Access where I have a ComboBox which displays a value taken from a table.

    I need to be able to have the first item be Blank so that when I first create a
    new record I can display the blank field and prevent the user from moving
    to a new record without changing the value.

    The place where I am having a problem lies in this code

    Form_EmailList.CmbActioned.SetFocus
    Form_EmailList.CmbActioned.ListIndex = TheRS.Fields(4).Value
    My problem is that where the value of TheRS.Fields(4).Value is 0
    Form_EmailList.CmbActioned.ListIndex is being set to -1

    Can anyone offer any suggestions?

    I am using the following code to load the data.
    This is called in Form_Load.

    Private Sub LoadEmailsUsed()
    ' Loads all used emails so that they can be quickly selected by the user if necessary
    Dim Idx As Long
    Dim EmailRS As ADODB.Recordset
    On Error GoTo Err_LoadEmailsUsed

    Form_EmailList.CmbActioned.RowSourceType = "Value List"
    ' Clear the List
    Do While Form_EmailList.CmbActioned.ListCount > 0
    Form_EmailList.CmbActioned.RemoveItem 0
    Loop

    ' Set the first Item in the list to a Blank
    Form_EmailList.CmbActioned.AddItem " ", 0

    Set EmailRS = New ADODB.Recordset
    EmailRS.Open "Emails", TheConn, adOpenKeyset, adLockPessimistic, adCmdTable

    EmailRS.MoveFirst
    Do Until (EmailRS.EOF) Or (EmailRS.BOF)
    Form_EmailList.CmbActioned.AddItem EmailRS.Fields(1), EmailRS.Fields(0)
    EmailRS.MoveNext
    Loop
    EmailRS.Close
    Set EmailRS = Nothing

    Exit_LoadEmailsUsed:
    On Error GoTo 0
    Exit Sub

    Err_LoadEmailsUsed:
    MsgBox "Form_EmailList - LoadEmailsUsed - " & Err.Number & " - " & Err.Description
    Resume Exit_LoadEmailsUsed

    End Sub
    Last edited by Torc; Aug 18th, 2008 at 05:55 AM.
    Signature Under Construction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width