Solved

Forcing new form to start from Form_Activate in VB6

Posted on 2003-10-27
8
904 Views
Last Modified: 2008-03-10
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.
0
Comment
Question by:simonblain
  • 2
  • 2
8 Comments
 
LVL 7

Accepted Solution

by:
_agj_ earned 150 total points
ID: 9625900
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
 

Author Comment

by:simonblain
ID: 9626235
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
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 150 total points
ID: 9630885
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
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9630887
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
 

Author Comment

by:simonblain
ID: 9631054
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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

803 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