|
-
Sep 17th, 2004, 11:37 AM
#1
Thread Starter
Member
combobox.change event fires when form opens. [Resolved]
I know that I can progam around this but still not quite sure why it happens. I have a project where a form has a combobox.change event that has code in it that gives the user a message that they are about to cause something to happen by changing the selection in the combo box. However, when the form opens the change event fires and the message box appears. The code is simple
Private Sub cboBox1_change()
msgbox "You just changed your selection"
End Sub
As the form opens the Message appears "You just changed your selection" and then after the user clicks ok the form opens. Why does the event Change fire as the form is opening? Is there a better way of handling this? Or do I just write come code to check to see if the form is open before the change event should occur? Thanks again for everyones help in the past. I continue to learn from this site.
Mike
Last edited by MIKEADKINS; Sep 17th, 2004 at 01:00 PM.
-
Sep 17th, 2004, 11:41 AM
#2
You may set some boolean flag while form is loading and check it within any procedure, also you will reset it at the end of your Form_Load event.
But I would like to see your Form_Load event procedure if you don't mind.
-
Sep 17th, 2004, 11:49 AM
#3
Easiest is just to check if the form is visible or not. Its not visible
until its finished loading.
VB Code:
Private Sub Combo1_Change()
If Form1.Visible = True Then
'Do stuf like validation of data entry or ??
Else
'Skips because the form is still loading.
End If
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 17th, 2004, 01:00 PM
#4
Re: combobox.change event fires when form opens.
Originally posted by MIKEADKINS
I know that I can progam around this but still not quite sure why it happens. I have a project where a form has a combobox.change event that has code in it that gives the user a message that they are about to cause something to happen by changing the selection in the combo box. However, when the form opens the change event fires and the message box appears. The code is simple
Private Sub cboBox1_change()
msgbox "You just changed your selection"
End Sub
As the form opens the Message appears "You just changed your selection" and then after the user clicks ok the form opens. Why does the event Change fire as the form is opening? Is there a better way of handling this? Or do I just write come code to check to see if the form is open before the change event should occur? Thanks again for everyones help in the past. I continue to learn from this site.
Mike
The Change event does not normally fire when the form loads. Put a breakpoint on the first line of code in the Change event and when the code gets there look at the Call Stack to see where you came from.
-
Sep 17th, 2004, 01:18 PM
#5
Thread Starter
Member
Discovered even more about combo boxes
The information that you provided did work. When the form opens the change event does not fire the code if it is placed within the If condition. However, I also found that clicking on the Combo List and selecting another choice does not kick off the change event code. What I did find was cboBox_Click() event does not fire until you make a new selection in a combo box. So the result was the following code that worked for me. But the other information is great to know also.
Private Sub Combo1_Click()
msgBox "You just changed something!"
End Sub
-
Sep 17th, 2004, 01:21 PM
#6
The combo1_change event is for when a user types something
into the combo box for style 0. The click event is when the user
actually clicks on an item in the dropdown list.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 17th, 2004, 01:35 PM
#7
Thread Starter
Member
cboBox_change event update
RhinoBull wanted to see my form_load code. So here it is along with the sub procedure. None of these should be affecting the cboBox_change event but I wanted to provide it anyway. What was suggested above did work. When the cboBox_Change() procedure checked to see if the form was visible it did not fire because the form had not loaded as stated by RobDog888. But as I said, what I was going after resulted in putting my msgbox code in the cboBox_Click() event. Because when I clicked on the cboBox and changed the selection the cboBox_Change() code did not fire. It just acts differently that what you would expect from the events. But as most of us know, if one thing does not work try something else. Thanks again for the updates. I learn so much from you all that thanks just never seems enough. Take care. Mike
VB Code:
Private Sub Form_Load()
Dim rsCDs As ADODB.Recordset
strPath = App.Path & "\datastore.mdb"
With Adodc2
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;Data Source=" & strPath & _
"; Mode=Read|Write"
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.CommandType = adCmdText
.RecordSource = "SELECT * FROM CD_Table"
.Refresh
End With
Adodc2.Recordset.MoveFirst
'Find the selected record and move the record pointer to that record.
Adodc2.Recordset.Find "RecordID = '" & gsRecordID & "'", 1, adSearchForward, 1
If Adodc2.Recordset.EOF Then
Adodc2.Recordset.MoveFirst
Else
End If
HideLoanInfo
cmdUpdate.Enabled = False
End Sub
Private Sub HideLoanInfo()
If chkOnLoan.Value = 1 Then
lblLoaned_to.Visible = True
txtLoaned_To.Visible = True
lblLoanDate.Visible = True
txtLoan_date.Visible = True
lbl_Loan_Due_Date.Visible = True
txtLoan_Date_Due.Visible = True
cmdReturnItem.Visible = True
Else
lblLoaned_to.Visible = False
txtLoaned_To.Visible = False
lblLoanDate.Visible = False
txtLoan_date.Visible = False
lbl_Loan_Due_Date.Visible = False
txtLoan_Date_Due.Visible = False
cmdReturnItem.Visible = False
End If
End Sub
Last edited by MIKEADKINS; Sep 17th, 2004 at 01:48 PM.
-
Sep 17th, 2004, 01:45 PM
#8
When you post code it would help others read it if you added [vbcode][/vbcode] tags.
-
Sep 17th, 2004, 01:52 PM
#9
Thread Starter
Member
Still learning. Thanks
Still learning. I did not know about the [Highlight=VB] tag. Wow, thats neat! My program is progressing nicely now and hope to have it completed this weekend. Thanks for everyones help again. Great Web Site. This is what the internet is all about. Sharing information and knowlege. Everyone take care and have a great weekend. If you are in West Virginia and you see someone at Starbucks with there laptop, coding away, its ME.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|