Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Forcing new form to start from Form_Activate in VB6

Posted on 2003-10-27
8
Medium Priority
?
971 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
5 Comments
 
LVL 7

Accepted Solution

by:
_agj_ earned 600 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 600 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

879 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