Forcing new form to start from Form_Activate in VB6

When I open a new form (frmOrder) from an already open form (frmMenu) the new form begins processing the code from "Private Sub cmdMeatsNew_Click()" instead of from the "Private Sub Form_Activate()". The code for the "Private Sub cmdMeatsNew_Click()" is as follows

Private Sub lstMeatsNew_Click()  '  ListBox selection within Enter Order STATE
   If OrderMax Then
      Exit Sub                OrderMax function
   End If
   DisplayItem lstMeatsNew    
End Sub

The "Private Sub Form_Activate()" code is as follows

Private Sub Form_Activate()
' Initialise Form State and Storage array
   strDay = Format(Day(Date), "00")
   strMonth = Format(Month(Date), "00")
   intTicketNo = 1
'need to conver this to obtain from the databse
   txtOrderNo.Text = strMonth & strDay & " " & Format(intTicketNo, "000")
   
adoMenuTable.Recordset.MoveFirst
   
With adoMenuTable.Recordset
    Do Until .EOF
        If !MNU_ITEM Like "1*" Then
            lstMeatsNew.AddItem Trim(!MNU_DESC)
        End If
        .MoveNext
    Loop
    .Close
End With

    SetOrderStart

End Sub


I am new to VB6 so I believe this is probably not to hard to overcome but am having major difficulty doing so. As far as I can tell, whenever I comment out the "Private Sub cmdMeatsNew_Click()" event this form begins from "Private Sub Form_Activate()" as running the program in break mode and forwarding through each line of code individually shows this. Does anybody have any ideas on this? If this is vague or more information or code is needed let me know.
simonblainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agj_Commented:
u mean that the procedure  lstMeatsNew_Click()  runs automatically....rite?

the listbox click event is fired automatcally when u do soemthing like setting its listIndex.

By this logic if u do the following in Form1 (some form),

1. form2.list1.listindex = 2  (or something else, that sets the current selected item)

then, the list1_click event in form2 is fired, and NOT the form_activate.
form_activate is fired only on form gettin the focus.


If u write ur form_activate stuff in form_load, it will run before the list_click and all such stuff.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simonblainAuthor Commented:
Thanks _agj_
you are right that lstMeatsNew_Click() procedure runs automatically but I am not firing that procedure from another form. In form1 I have the following:

Private Sub mnuOperationsOE_Click()
    form2.Show 1
End Sub

This opens up form2 but I don't intend it is also run the lstMeatsNew_Click() procedure automatically. On opening form2 I want the list box lstMeatsNew to populate its content from a MS Access database. I have placed the following code in Form_Activate() and then Form_Load() as you suggested to do this:


With adoMenuTable.Recordset
    Do Until .EOF
        If !MNU_ITEM Like "1*" Then
            lstMeatsNew.AddItem Trim(!MNU_DESC)
        End If
        .MoveNext
    Loop
    .Close
End With


This seems to work fine for filling up the list boxes. However when I place this code:


Private Sub lstMeatsNew_Click()  

If OrderMax Then
      Exit Sub                
   End If
   DisplayItem lstMeatsNew    
End Sub


into form2 I get the problem where form2 opens from the previously shown code from form1 and then automatically wants to run the procedure lstMeatsNew_Click() regardless of if I place the list box population code shown before in either form_load or form_activate for form2.
Any thoughts
0
fantasy1001Commented:
I am not sure what is the content of SetOrderStart. If within the function, it set the list index, then the clicked event will fire. There aer another possibility, some people have some kind of "overflow" on their keyboard. You can try this

public passonce as integer

in the end of form_activate
passonce = 1

in the start of lstmeatsnew_click
if passonce then
   passonce
   exit sub
end if
0
fantasy1001Commented:
I am not sure what is the content of SetOrderStart. If within the function, it set the list index, then the clicked event will fire. There aer another possibility, some people have some kind of "overflow" on their keyboard. You can try this

public passonce as integer

in the end of form_activate
passonce = 1

in the start of lstmeatsnew_click
if passonce then
   passonce = 0
   exit sub
end if
0
simonblainAuthor Commented:
I will give this a try,
the content of seOrderStart is as follows


Private Sub SetOrderStart()    
   Dim n As Integer
   For n = 1 To 20
      strOrder(n) = ""
   Next n
   intItemNo = 0
   intItems = 0
   picOrder.Cls
   
   cmdPrint.Enabled = False      
   cmdCancelItem.Enabled = False
   cmdCancelOrder.Enabled = False
   cmdExit.Enabled = True
End Sub

Does this provide any more information for you? Is there any other info that may be of use?
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.