I was wondering how I could get a form to load and populate the textboxes without triggering the "Change" event on the textbox.
Once the form is loaded, then I wanted to use the "Change" event.
Printable View
I was wondering how I could get a form to load and populate the textboxes without triggering the "Change" event on the textbox.
Once the form is loaded, then I wanted to use the "Change" event.
if you cant hardcode the textbox value you could have a private boolean to say if the form is loaded or not.
VB Code:
Option Explicit Private loaded As Boolean '------------------------ Private Sub Form_Load() Text1.Text = "some text" loaded = True End Sub '------------------------ Private Sub Text1_Change() If loaded = True Then 'your code End If End Sub
casey.
You could create a boolean and turn the boolean to true once the textboxes are populated. Then on each textbox change event put everything inside: 'If boolean = True then', so that they are only triggered when the boolean is true, obviously. So is that what you are looking for?
Hi,
You can try this.
VB Code:
Option Explicit Dim Loading As Boolean Private Sub Form_Load() Loading = True Text1.Text = "loading" Loading = False End Sub Private Sub Text1_Change() If Loading Then Exit Sub Else MsgBox "Change event fired" End Sub
Have a good one!
BK
I wonder who removed my last post...sorry if it offended anyone, was just joking =P.
It didn't work when I tried it vbasicgirl's way. I haven't tried the others yet.
every time the form loads, it triggers the msgbox and "ButtonChange" has obviously triggered.VB Code:
' **************** ' This is in frmMaterials ' **************** Private Sub flxgrdMaterials_DblClick() frmMatDialog.PopMatEdit (flxgrdMaterials.TextMatrix(flxgrdMaterials.RowSel, 0)) frmMatDialog.Show vbModal End Sub ' **************** ' this is in frmMatDialog ' **************** Private Sub Form_Load() cmdSave.Enabled = False cmdSave.Visible = False cmdCancel.Caption = "Close" frmMain.Visible = False ' for some reason my other mdi form shows up :ehh: End Sub Public sub PopMatEdit (ByVal myMatToEdit As Integer) ' I retireve data from a database and use "rs" as the recordset (not needed for this question) If IsNull(rs.Fields("Date").Value) = True Then txtDate.Text = "" Else txtDate.Text = rs.Fields("Date").Value End If End Sub Private Sub txtDate_Change() If lblDateChck.Caption <> txtDate.Text Then Call ButtonChange MsgBox "txtDate_Change" End If End Sub Private Sub ButtonChange() cmdSave.Enabled = True cmdSave.Visible = True cmdCancel.Caption = "Cancel" End Sub
I don't see where you are incorporating vbasicgirl's suggestion of using a Boolean, so how is her suggestion not working?
beengie, i dont see a boolean anywhere in your code. The reason you MDI form shows up is because frmMain is an mdi child.
I tried the code and then removed it. that is why I included the code.