question

PaulGoldstein-4693 avatar image
0 Votes"
PaulGoldstein-4693 asked PaulGoldstein-4693 commented

Textbox in TabPage not always loading data from table

I have a form linked to an Access table.
The table contains Student information.
Because of the vast amount of information for each student, I have created a TabControl to handle information about the student’s parents.
After listing the parents name as two separate textboxes on the form: txtParent1 and txtParent2, the TabControl "tcParentContacts" is directly to the right of the two TextBoxes.
There are 4 TabPages in tcParentContacts:
tabpgCellPhone, which contains: mtxtParent1Cell (MaskedTextBox), and mtxtParent2Cell (MaskedTextBox)
tabpgHomePhone, which contains: mtxtParent1Home (MaskedTextBox), and mtxtParent2Home (MaskedTextBox)
tabpgWorkPhone, which contains: mtxtParent1Work (MaskedTextBox), and mtxtParent2Work (MaskedTextBox)
and tabpgEmail, which contains: txtParent1Email (TextBox), and txtParent2Email (TextBox)

116006-tcparentcontacts.png

For some reason…which I haven’t as yet figured out…when navigating to a different record in the table, the Email fields are not updating to the information in the currently displayed record. This field is used by another form that is opened when the current record is displayed to extract communications with the parents. The problem is that the sub-form is using the wrong Email address to pull in Exchange info… it’s using the Email address from a previously displayed Student that was navigated to before the current student.

Any ideas would be greatly appreciated

Thank you for your time in advance,
Paul Goldstein





windows-forms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PaulGoldstein-4693,
>>when navigating to a different record in the table, the Email fields are not updating to the information in the currently displayed record.
When you navigate to different records in the table, does the email field always stay the same? Or does it show that different results are just data mismatches?
I suggest you first set a breakpoint to check your Email when it is retrieved from the table. It is best to provide some of your relevant code to reproduce the problem so as to find the cause accurately.
Best Regards,
Daniel Zhang

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

Question, are you reading data from the database into a DataSet then setting the DataSet to a BindingSource then data binding to form controls? What happens when changing records without the other form open?

If using a BindingSource you can subscribe to PositionChanged event and look at the raw data by casting Current property of the BindingSource to (if working with a DataTable) a DataRowView then access the Row followed by properties of the row.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PaulGoldstein-4693 avatar image
0 Votes"
PaulGoldstein-4693 answered PaulGoldstein-4693 commented

Hi Karen (@karenpayneoregon),

 Thank you for writing.
 This is what I am doing:

  1. I have an Access Table: tblBMList

  2. The database contains a query, qryBMList, that sorts the table by LastName, FirstName and also adds a field FirstName & " " & LastName as StudentName for other purposes.

  3. I dragged qryBMList onto a blank form, frmBMList which then created a BindingNavigator and a DataGridView

  4. I deleted the DataGridView since I want to view table one record at a time…and since each record contains vast amounts of data and also uses sub-Tables that contain other "transactional" data.

  5. I then either: A) Dragged individual fields from the Query onto the form, or used the Toolbox for: DateTimePickers, MaskedTextBoxes, CheckBoxes, etc. and then assigned them corresponding fields in tblBMList by using the DataBindings in the Properties window. This is how I created the fields in the TabControl.

  6. In addition to the MoveFirst, MovePrevious, MoveNext, MoveLast Item buttons in the BindingNavigator, I also added a ToolStripComboBox: cboBMList to jump directly to a specific Student’s record. cboBMList is initialized by using the following code: Me.cboBMList.ComboBox.DataSource = Me.QryBMListBindingSource Me.cboBMList.ComboBox.DisplayMember = "StudentName" Me.cboBMList.ComboBox.ValueMember = "RecordKey"
    I use the Sub QryBMListBindingSource_CurrentChanged to populate the non-Bound fields in the form.

I placed a debugging loop in that Sub to dump out the values of the fields in the TabControl:

         Dim tabCurrent As TabPage
         Dim ctlCurrent As Control
         Debug.Print("Debugging Me.tcParentContacts")
         For Each tabCurrent In Me.tcParentContacts.TabPages
             Debug.Print($"In: {tabCurrent.Name}")
             For Each ctlCurrent In tabCurrent.Controls
                 Debug.Print($"In: {ctlCurrent.Name}, {ctlCurrent.Text}")
             Next
         Next

This is what I found:
The only fields that always get printed, are the two fields in the first tab: tabpgCellPhone.
The other fields only get printed if I pre-Select one of the other TabPages before navigating to it (the fields of tabpgCellPhone always get printed regardless of which TabPage is selected.

So, I modified the routine and added two lines of code before the loop:

         Dim tabSelected As TabPage
         tabSelected = Me.tcParentContacts.SelectedTab

and inserted another line withing the loop:

             Me.tcParentContacts.SelectedTab = tabCurrent

and then, one more line after the loop to go back to the originally displayed TabPage:

         Me.tcParentContacts.SelectedTab = tabSelected

This had the desired effect of displaying all of the Parent1 and Parent2 information fields.

In addition, I cleaned up some code that was being fired inadvertently when some of the Date fields were being updated by the when the navigation changed, but that had independent TextChanged properties that would update other non-Bound fields in the form. Once I did that, then the Parent information…specifically the Email field problem went away.

So I am left with one question: when I call the sub-Form that does the email inquiry, I do have the code select the Email TabPage in order to get to the Email fields.
Is there any other way of getting to the data…other than: QryBMListBindingSource.Current("<Email Field Name>").ToString ?

Again, thank you for your time in advance.

Paul Goldstein

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @@PaulGoldstein-4693,
You can also get current item via BindingSource.Position property.
Best Regards,
Daniel Zhang


0 Votes 0 ·

Hi Daniel,
Thank you for writing.
Unfortunately, I don’t think that’s going to help.
That would imply that the user was using the data stored in the table. However, if the user entered a new value, but didn’t save the record yet…then the previous value would be used instead of the new (unsaved) value.
I guess that I’m going to have to stick with having the code:

  1. Store the currently selected TabPage into a variable

  2. Select the Email TabPage

  3. Read the Email values: to be passed to the sub-Form

  4. Select the previously stored TabPage from the variable (so that it “Resets” the Form’s appearance)

  5. Open the sub-Form

    Thanks again for your suggestion.
    Take care,
    Paul Goldstein








0 Votes 0 ·