Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Combobox and Textbox Change Events

Posted on 2002-05-17
2
Medium Priority
?
619 Views
Last Modified: 2012-05-04
I'm using VB6 against an SQL Server database.
I'm having a minor problem and I think it has to do with the sequencing of my code.
I have a textbox, combobox, and a datagrid.
All are blank when the form loads.
The textbox will contain a code, the combobox to the right will contain a description and the grid below will be populated with the data from this code and/or description.
The user can enter a code in the textbox or choose a selection from the combobox to poulate the grid.
I'm having a problem getting them in sync.

When the user enters a value in the textbox, that part works:  that value is searched and a description is brought back in the combobox and the grid populated.

But, when I search from the combobox, the textfield is filled correctly and the grid filled correctly but then the combobox is cleared - it's not set to the correct description.
When I step thru the debugger, I see where my combobox is getting cleared but I can't seem to get the code right.
--------------------------------------------------------
Here's the code from my combobox_click event and then the code for the txt_change event if that will help.
DataInquire is the function that populates the grid.
----------------------------------------------------
Private Sub cmbAgencyCode_Click()
Dim Done As Boolean
    Done = False
    If Not (rsAgencies.BOF And rsAgencies.EOF) Then
        rsAgencies.MoveFirst
        While Not rsAgencies.EOF And Not Done
            If rsAgencies.Fields("description") = cmbAgencyCode.Text Then
                txtAgency.Text = rsAgencies.Fields("code")
                Done = True
            End If
            If Not Done Then rsAgencies.MoveNext
        Wend
    End If
       
    DataInquire
    txtMessage = "Press ADD button or Double click on item you want to MODIFY or DELETE"
    cmbAgencyCode = UCase(cmbAgencyCode)
End Sub
---------------------------------------------------------
Private Sub txtAgency_Change()
    If Len(txtAgency) = 5 Then
        Call txtAgency_Validate(False)
        If txtAgency = "" Then Exit Sub
    End If
End Sub
---------------------------------------------------------
Private Sub txtAgency_Validate(Cancel As Boolean)
Dim Done As Boolean
    txtAgency = UCase$(txtAgency)
    cmbAgencyCode.Clear
    rsAgencies.MoveFirst
        While Not rsAgencies.EOF
            cmbAgencyCode.AddItem rsAgencies!Description
            rsAgencies.MoveNext
        Wend
    If txtAgency <> "" Then
        rsAgencies.MoveFirst
        Done = False
        While Not rsAgencies.EOF And Not Done
            If txtAgency = rsAgencies.Fields("code") Then
                cmbAgencyCode.Text = rsAgencies.Fields("description")
                Cancel = False
                Done = True
            Else
                Cancel = True
            End If
            If Not Done Then rsAgencies.MoveNext
        Wend
        If Cancel = True Then
            MsgBox "Invalid Agency Code"
            txtAgency = ""
            txtAgency.SetFocus
        End If
    End If
End Sub
---------------------------------------------------------


Thanks in Advance.
John
0
Comment
Question by:jtrapat1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 800 total points
ID: 7016317
Change your click event code to this and it will all run smoothly:

Private Sub cmbAgencyCode_Click()
Dim Done As Boolean
   Done = False
   Dim intL As Integer
   If Not (rsAgencies.BOF And rsAgencies.EOF) Then
       rsAgencies.MoveFirst
       While Not rsAgencies.EOF And Not Done
           If rsAgencies.Fields("description") = cmbAgencyCode.Text Then
               txtAgency.Text = rsAgencies.Fields("code")
               Done = True
            Else
             intL = intL + 1
           End If
           If Not Done Then rsAgencies.MoveNext
       Wend
   End If
   cmbAgencyCode.ListIndex = intL
'   DataInquire
'   txtMessage = "Press ADD button or Double click on item you want to MODIFY or DELETE"
'   cmbAgencyCode = UCase(cmbAgencyCode)
End Sub
0
 

Author Comment

by:jtrapat1
ID: 7017008
TimCottee,

Thanks for the help; that fixed the problem.
Related to this, there has been something that is bugging me about this project and maybe you could answer it.
The combobox I'm using will not recognize the _Change() Event.  

I tried different styles such as Dropdown List and Dropdown Combo but it still will not work.
I checked thru all of the properties but none of them were disabled to cause this problem.
Do you have any idea why this event would be disabled?

I've had to use the _Click event to take the place of the _Change event.

Thanks
John
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question