Results 1 to 4 of 4

Thread: Combo Box Text [resolved]

  1. #1

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Combo Box Text [resolved]

    I'm adding a record to a db and setting a combo boxs text to the newly added record. I haven't run into this problem before, but each time I exit the sub, the combo box text dissappears.

    VB Code:
    1. Private Sub cmbPrimaryAffiliation_Click()
    2.     Dim currentSecondary As String
    3.    
    4.     currentSecondary = cmbSecondary.text
    5.    
    6.     If cmbPrimaryAffiliation.text <> "" Then
    7.         If cmbPrimaryAffiliation.text = "Add A Company" Then
    8.             leadsAdding = True
    9.             frmAddCompany.Show vbModal
    10.             If rs.State = adStateOpen Then rs.Close
    11.             rs.Open "SELECT * FROM tblcompany ORDER BY company", cn, adOpenKeyset, adLockReadOnly, adCmdText
    12.             cmbPrimaryAffiliation.Clear
    13.             cmbSecondary.Clear
    14.             Do Until rs.EOF = True
    15.                 cmbPrimaryAffiliation.AddItem rs!company
    16.                 cmbSecondary.AddItem rs!company
    17.                 rs.MoveNext
    18.             Loop
    19.             cmbPrimaryAffiliation.AddItem "Add A Company"
    20.             cmbSecondary.AddItem "Add A Company"
    21.             cmbPrimaryAffiliation.text = frmAddCompany.compName
    22.             cmbSecondary.text = currentSecondary
    23.             leadsAdding = False
    24.         End If
    25.     End If
    26. End Sub

    The text is visible after the .Text line, but when I get to End Sub - it dissappears. Any ideas?

    Thanks
    Last edited by demotivater; Jun 30th, 2004 at 01:47 PM.

  2. #2
    Hyperactive Member
    Join Date
    May 2003
    Posts
    401
    Move this line:
    currentSecondary = cmbSecondary.text

    just before EndSub in ur code. I think that should work.
    Enjoy!!!
    apps_tech

  3. #3

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627
    Actually, that's kind of unrelated. It's the cmbPrimaryAffiliation I'm trying to set the text for. It sets fine, but when the sub ends, it's gone. I don't have any other subs for got focus, lost focus or anything like that. Just this one click sub that allows the user to add a new company. I'm then trying to set the combo box to the company the user added. ie: cmbPrimaryAffiliation.text = frmAddCompany.compName, which works fine and adds the text. As soon as I hit end sub it's gone.

  4. #4

    Thread Starter
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627
    I still have no idea why the text was disappearing, but anyway...
    I'm going this route instead in case someone needs this in the future.

    VB Code:
    1. 'API to search company combo boxes after adding new company
    2. Private Declare Function SendMessage _
    3.                 Lib "user32" _
    4.                 Alias "SendMessageA" _
    5.                 (ByVal hWnd As Long, _
    6.                  ByVal wMsg As Long, _
    7.                  ByVal wParam As Integer, _
    8.                  lParam As Any) As Long
    9.  
    10. Private Const CB_FINDSTRING = &H14C
    11.  
    12.  
    13. Private Sub cmbPrimaryAffiliation_Click()
    14.     Dim currentSecondary As String
    15.     Dim newName As String
    16.     Dim intIndex As Integer
    17.    
    18.     currentSecondary = cmbSecondary.text
    19.    
    20.     If cmbPrimaryAffiliation.text <> "" Then
    21.         If cmbPrimaryAffiliation.text = "Add A Company" Then
    22.             leadsAdding = True
    23.             frmAddCompany.Show vbModal
    24.             newName = frmAddCompany.compName
    25.             If rs.State = adStateOpen Then rs.Close
    26.             rs.Open "SELECT * FROM tblcompany ORDER BY company", cn, adOpenKeyset, adLockReadOnly, adCmdText
    27.             cmbPrimaryAffiliation.Clear
    28.             cmbSecondary.Clear
    29.             Do Until rs.EOF = True
    30.                 cmbPrimaryAffiliation.AddItem rs!company
    31.                 cmbSecondary.AddItem rs!company
    32.                 rs.MoveNext
    33.             Loop
    34.             If rs.State = adStateOpen Then rs.Close
    35.             cmbPrimaryAffiliation.AddItem "Add A Company"
    36.             cmbSecondary.AddItem "Add A Company"
    37.             'find the newname in the combo box
    38.             intIndex = SendMessage(cmbPrimaryAffiliation.hWnd, CB_FINDSTRING, -1, ByVal newName)
    39.             cmbPrimaryAffiliation.ListIndex = intIndex
    40.             'cmbPrimaryAffiliation.text = newName <--- this won't work for some reason
    41.             cmbSecondary.text = currentSecondary
    42.             leadsAdding = False
    43.         End If
    44.     End If
    45. End Sub

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