View Single Post
 
Old 05-05-2016, 12:36 PM
MisterChips MisterChips is offline Windows 10 Office 2016
Novice
 
Join Date: May 2016
Posts: 1
MisterChips is on a distinguished road
Default Unable to get a User Form to write changes

Sirs,
I am reasonable conversant with VBA in Access databases, but now have a need to create User Forms to make spreadsheets easier to update.
I have a problem with a User Form that I do not understand.
I have a number of text boxes on the user form that I populate from a worksheet.
Putting the data into the form’s textboxes works well , the data displays exactly as it is in the workbook, and the text boxes accept changes.
The intention is to change the data in the text boxes and write the changes back to the worksheet.
After making a change, I do this by clicking on a command button5 which runs the following snipped of code.

Private Sub CommandButton5_Click() ' SAVE button
MsgBox MO.Text ‘ First MsgBox
PutData
End Sub

Private Sub PutData()
MsgBox MO.Text ‘ Second MsgBox
Cells(r, 1).Value = LodgeNo.Text
Cells(r, 2).Value = LodgeName.Text
Cells(r, 3).Value = WM.Text
Cells(r, 4).Value = SW.Text
Cells(r, 5).Value = JW.Text
MsgBox MO.Text ‘ Third MsgBox
Cells(r, 6).Value = MO.Text
Cells(r, 7).Value = SO.Text
End sub

I am using MO.text as text box to investigate

The workbook cell has "Dave Parker" in it.
When loaded into the user form MO.text has “Dave Parker” in it.
I change the data to “John Smith” and click on button5 (save)
MsgBox one shows MO.Text as being “John Smith”
MsgBox two shows MO.Text as being “John Smith”
(Both of which I expect and am happy with)
MsgBox three, however, shows MO.Text as being “Dave Parker” (again)
…… and the worksheet cell remains “Dave Parker”
My question is what is wrong with my code that causes the data to revert to the original text in the worksheet?
.... rather than the udpdated text in the user form.
Reply With Quote