Advertisement

07.08.2005 at 12:07PM PDT, ID: 21485230
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Picture box change event firing for no apparent reason.

Asked by monacoassociates in VB Controls

Tags: , , , ,

In our Visual Basic 6 application, one of the forms has a picture box that displays a photograph (stored in the database in bitmap format).  During the form load process, the picture box change event fires, as expected, at the point when the picture is loaded.  However immediately after the form load process completes, the picture box change event fires again.  There is code in that change event that we DO NOT want to execute at that point in the program.  So the question is, what is causing the change event to execute at that point in the code and how can we get control of it?  

Here is the code (the form_load subroutine calls SetMainMenuComboBoxSelection (with source=TOOLBAR) , which calls ChildCbox_click, which calls LoadPhoto)  The picture1_change event fires at "Set DATA2.Recordset = photoRS" in the LoadPhoto subroutine, then it fires again immediately after control has returned to form_load and LOAD_EXIT: Exit Sub has executed.  (This code was working correctly in the past.  In our latest program version we upgraded to DAO 3.6, and we had to add a recordset to get our data control to work.  We can't think of any reason that would cause this problem.)

Private Sub form_Load()
  Dim Action As Integer
 
  On Error GoTo LOAD_ERROR
 
  Screen.MousePointer = 11

' no tabstops
' set common controls: first control on form to set focus
'                      combobox on main menu
  Set mycbox = frmMainMenu.cboxProfile
  SSTab1.Tab = 0
  SSTab1.TabVisible(4) = False
  Set myfirstfocus = picTfirst_name
  'Load form procedure (formname, C=Child D = Dialog, Width, Height)
  Call LoadFormProc(Me, "C", 9525, 5195)   'H changed from 5100, W changed from 9480  9/15/04 Lou
  'mainmenu combo box
  Call LoadComboProc("consumers", mycbox)
  LoadSmartCombos
  'Load Dumb Combos
  Call LoadDumbCombos
  'Form SQL--this is the SQL used throughout the form
  Formsql$ = "select * from [BACKGROUND (CONSUMER)] "
  wclause$ = " WHERE [SOCIAL SECURITY NUMBER] = '" & ssn(str$(mycbox.ItemData(mycbox.ListIndex))) & "';"

   
  'Prepare International
  SetMyWording

  countForm = countForm + 1
  Call SetMainMenuComboBoxSelection(mycbox, Me)
LOAD_EXIT:
    Screen.MousePointer = 0
    Exit Sub

LOAD_ERROR:
    Action = errors(Err)
    Select Case Action
        Case 0
            Resume
        Case 1
            Resume Next
        Case 2, 3
            GoTo LOAD_EXIT
        End Select
End Sub



Public Sub SetMainMenuComboBoxSelection(c As Control, f As Form)
  'This routine will fill a combo box (consumer name) on the
  'main menu with the same consumer on the previous form
  '1  a toolbar button for consumer information
  '   was pressed and
  '2  there is a name selected in cbox_xxxxx
  Dim matchSSN As Long, i%
 

  If source = "TOOLBAR" And countForm > 1 Then  'if user click on the shortcut
    'THERE IS A SELECTION IN frmMainMenu.cboxProfile
    Select Case frmMainMenu.ActiveForm.Name
      Case "frmProfile"
        matchSSN = frmMainMenu.cboxProfile.ItemData(frmMainMenu.cboxProfile.ListIndex)
      Case "frmBudget"
        matchSSN = frmMainMenu.cboxBudget.ItemData(frmMainMenu.cboxBudget.ListIndex)
      Case "frmEducation"
        matchSSN = frmMainMenu.cboxEducation.ItemData(frmMainMenu.cboxEducation.ListIndex)
      Case "frmEmployment"
        matchSSN = frmMainMenu.cboxEmployment.ItemData(frmMainMenu.cboxEmployment.ListIndex)
      Case "frmIncident"
        matchSSN = frmMainMenu.cboxIncident.ItemData(frmMainMenu.cboxIncident.ListIndex)
      Case "frmMedications"
        matchSSN = frmMainMenu.cboxMedications.ItemData(frmMainMenu.cboxMedications.ListIndex)
      Case "frmNotes"
        matchSSN = frmMainMenu.cboxNotes.ItemData(frmMainMenu.cboxNotes.ListIndex)
      Case "frmRelationships"
        matchSSN = frmMainMenu.cboxRelationships.ItemData(frmMainMenu.cboxRelationships.ListIndex)
      Case "frmRoutines"
        matchSSN = frmMainMenu.cboxRoutines.ItemData(frmMainMenu.cboxRoutines.ListIndex)
      Case "frmServiceParticipation"
        matchSSN = frmMainMenu.cboxProgramParticipation.ItemData(frmMainMenu.cboxProgramParticipation.ListIndex)
    End Select
     
    For i = 0 To c.ListCount - 1
      If c.ItemData(i) = matchSSN Then
        c.ListIndex = i
        Call f.ChildCboxClick
        Exit For
      End If
    Next
    source = ""
  End If
End Sub

Public Sub ChildCboxClick()
  Dim Action%
  On Error GoTo ChildCboxClickERROR

  'make sure an item was selected
    If mycbox.ListIndex = -1 Then GoTo ChildCboxClickEXIT
  'set mousepointer
    Screen.MousePointer = 11
  'initial settings for fields
    Call ClearFormControlsProc(Me)
    Call LockFormControlsProc(Me, True)
  'set sql
    wclause$ = " WHERE [SOCIAL SECURITY NUMBER] = '" & ssn(str$(mycbox.ItemData(mycbox.ListIndex))) & "';"
   
  'call reader routine
    Call Reader(Me, Formsql & wclause$, "")
  'special case---
    'load photo
    Call LoadPhoto
    'load combos with relationship information
    Call LoadRelationshipsProc
    Call SetSelectedNames
    'make sure ssn field is not enabled
    picTssn.Enabled = False
  'set form caption
    Me.caption = "Consumer Profile [" & mycbox.text & "]"
  'set form tag
  '  Tag = False
   
  'find the age of this consumer (not saved into database)
    findAge
  'set form tag 'should be after all other events in module  Lou  6/15/05
    Tag = False

ChildCboxClickEXIT:
    Screen.MousePointer = 0
    Exit Sub

ChildCboxClickERROR:
    Action = errors(Err)
    Select Case Action
        Case 0
            Resume
        Case 1
            Resume Next
        Case 2, 3
            GoTo ChildCboxClickEXIT
    End Select

End Sub



Private Sub LoadPhoto()
    Dim MYTABLE As Recordset, id$
    Dim photoRS As dao.Recordset  'open recordset and set data control to it for compatibility with Access 2000 (jet 4.0)  4/28/05 Lou
    Set photoRS = mydb.OpenRecordset("SELECT * FROM photographs WHERE ssn = '" & ssn(str$(mycbox.ItemData(mycbox.ListIndex))) & "';")
    photoRS.Requery
    Set DATA2.Recordset = photoRS
   ' DATA2.RecordSource = "SELECT * FROM photographs WHERE ssn = '" & ssn(str$(mycbox.ItemData(mycbox.ListIndex))) & "';"
   ' DATA2.Refresh
    DoEvents
    'Make sure there is a photo record
    If DATA2.Recordset.RecordCount < 1 Then
      'add consumer photo
      Set MYTABLE = mydb.OpenRecordset("PHOTOGRAPHS", dbOpenTable)
          MYTABLE.AddNew
              MYTABLE!ssn = ssn(str$(mycbox.ItemData(mycbox.ListIndex)))
          MYTABLE.Update
          MYTABLE.MoveLast
          If MIRRORTRANSACTIONS = True Then
              id$ = MYTABLE!ssn
              Call RecordTransaction("Photographs", id$, "A")
          End If
      MYTABLE.Close
      Set photoRS = mydb.OpenRecordset("SELECT * FROM photographs WHERE ssn = '" & ssn(str$(mycbox.ItemData(mycbox.ListIndex))) & "';")
      photoRS.Requery
      Set DATA2.Recordset = photoRS
     ' DATA2.RecordSource = "SELECT * FROM photographs WHERE ssn = '" & ssn(str$(mycbox.ItemData(mycbox.ListIndex))) & "';"
     ' DATA2.Refresh
      DoEvents
    End If
    Picture1.Tag = False
End Sub

Start Free Trial
[+][-]07.08.2005 at 12:59PM PDT, ID: 14400313

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2005 at 01:08PM PDT, ID: 14400374

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2005 at 10:51AM PDT, ID: 14407644

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.17.2006 at 02:53PM PST, ID: 16221176

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.17.2006 at 06:37PM PST, ID: 16222293

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]03.21.2006 at 01:14PM PST, ID: 16251685

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: VB Controls
Tags: box, change, child, event, firing
Sign Up Now!
Solution Provided By: GranMod
Participating Experts: 3
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32