Solved

Combobox and Textbox Change Events

Posted on 2002-05-17
2
617 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 200 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month7 days, 14 hours left to enroll

617 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