|
-
Jun 30th, 2004, 11:10 AM
#1
Thread Starter
Fanatic Member
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:
Private Sub cmbPrimaryAffiliation_Click()
Dim currentSecondary As String
currentSecondary = cmbSecondary.text
If cmbPrimaryAffiliation.text <> "" Then
If cmbPrimaryAffiliation.text = "Add A Company" Then
leadsAdding = True
frmAddCompany.Show vbModal
If rs.State = adStateOpen Then rs.Close
rs.Open "SELECT * FROM tblcompany ORDER BY company", cn, adOpenKeyset, adLockReadOnly, adCmdText
cmbPrimaryAffiliation.Clear
cmbSecondary.Clear
Do Until rs.EOF = True
cmbPrimaryAffiliation.AddItem rs!company
cmbSecondary.AddItem rs!company
rs.MoveNext
Loop
cmbPrimaryAffiliation.AddItem "Add A Company"
cmbSecondary.AddItem "Add A Company"
cmbPrimaryAffiliation.text = frmAddCompany.compName
cmbSecondary.text = currentSecondary
leadsAdding = False
End If
End If
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.
-
Jun 30th, 2004, 11:26 AM
#2
Hyperactive Member
Move this line:
currentSecondary = cmbSecondary.text
just before EndSub in ur code. I think that should work.
-
Jun 30th, 2004, 11:30 AM
#3
Thread Starter
Fanatic Member
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.
-
Jun 30th, 2004, 01:47 PM
#4
Thread Starter
Fanatic Member
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:
'API to search company combo boxes after adding new company
Private Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
lParam As Any) As Long
Private Const CB_FINDSTRING = &H14C
Private Sub cmbPrimaryAffiliation_Click()
Dim currentSecondary As String
Dim newName As String
Dim intIndex As Integer
currentSecondary = cmbSecondary.text
If cmbPrimaryAffiliation.text <> "" Then
If cmbPrimaryAffiliation.text = "Add A Company" Then
leadsAdding = True
frmAddCompany.Show vbModal
newName = frmAddCompany.compName
If rs.State = adStateOpen Then rs.Close
rs.Open "SELECT * FROM tblcompany ORDER BY company", cn, adOpenKeyset, adLockReadOnly, adCmdText
cmbPrimaryAffiliation.Clear
cmbSecondary.Clear
Do Until rs.EOF = True
cmbPrimaryAffiliation.AddItem rs!company
cmbSecondary.AddItem rs!company
rs.MoveNext
Loop
If rs.State = adStateOpen Then rs.Close
cmbPrimaryAffiliation.AddItem "Add A Company"
cmbSecondary.AddItem "Add A Company"
'find the newname in the combo box
intIndex = SendMessage(cmbPrimaryAffiliation.hWnd, CB_FINDSTRING, -1, ByVal newName)
cmbPrimaryAffiliation.ListIndex = intIndex
'cmbPrimaryAffiliation.text = newName <--- this won't work for some reason
cmbSecondary.text = currentSecondary
leadsAdding = False
End If
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|