Solved

Combobox and Textbox Change Events

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

738 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