The question(s) is:
I’ve created a multipage userform, with the option to submit data at the bottom of each page.
On clicking submit on the first page, a uniqueID is created for this record and this id along with the rest of the data on this page is written to a worksheet
What I’m having trouble doing is writing data to the same worksheet row at a later stage in the multipage userform, and looking up the data ta later date and enable editing
The code for the first page of the userform Submit Command button is below:
Private Sub btnSetupSubmit_Click()
'Check for all required entries
If tboSetupUserName = "" Or cboSetupBrand.Value = "" _
Or tboSetupDate = "" Or cboSetupPageType.Value = "" Or tboSetupPageTitle = "" _
Or tboSetupPageURL = "" Or tboSetupObjective = "" Or tboSetupMethod = "" Then
'Notify user if entries are missing
MsgBox "You must complete all fields on this page", vbCritical, "hmmm, want to try that again?"
Me.tboSetupUserName.SetFocus
Exit Sub
Else
'rest of code
'write this page data to worksheet
Dim LastRow As Object
Set LastRow = Sheet1.Range("a104857").End(xlUp)
'generate and write UniqueID
LastRow.Offset(1, 0).Value = LastRow.Offset(0, 0).Value + 1
'write UniqueID to form
tboSetupUniqueID.Text = LastRow.Offset(1, 0).Value
'write rest of data to worksheet
LastRow.Offset(1, 1).Value = tboSetupUserName.Text
LastRow.Offset(1, 2).Value = cboSetupBrand.Text
LastRow.Offset(1, 3).Value = tboSetupDate.Text
LastRow.Offset(1, 4).Value = cboSetupPageType.Text
LastRow.Offset(1, 5).Value = tboSetupPageTitle.Text
LastRow.Offset(1, 6).Value = tboSetupPageURL.Text
LastRow.Offset(1, 7).Value = tboSetupObjective.Text
LastRow.Offset(1, 8).Value = tboSetupMethod.Text
'notification to user
MsgBox "Data written to Worksheet", vbInformation, "Congratulations!"
'write UniqueID to tboPreChangeUniqueID.Value
tboPreChangeUniqueID.Value = tboSetupUniqueID.Value
'lock data
tboSetupUserName.Locked = True
cboSetupBrand.Locked = True
tboSetupDate.Locked = True
cboSetupPageType.Locked = True
tboSetupPageTitle.Locked = True
tboSetupPageURL.Locked = True
tboSetupObjective.Locked = True
tboSetupMethod.Locked = True
tboPreChangeUniqueID.Locked = True
'make Pre-Change Data page accessible
MultiPage1.pagPreChangeData.Visible = True
'take user to Pre-Change Data page
MultiPage1.Value = 1
End If
End Sub
The second page in the userform is MultiPage1 and this also has text and combo boxes on it, and when users input data into these boxes I need it to appear on the same row as specified by the uniqueID (tboSetupUniqueID.Value)
Hope someone can help
Thanks,
Ben
- How do I get a userform to write data to a specific worksheet row based on a uniqueID in the first cell of that row (this id is created automatically in an earlier part of the process)?
- How do I populate the content of a userform with data from a worksheet (located by entering the uniqueID) and then allow users to edit it?
I’ve created a multipage userform, with the option to submit data at the bottom of each page.
On clicking submit on the first page, a uniqueID is created for this record and this id along with the rest of the data on this page is written to a worksheet
What I’m having trouble doing is writing data to the same worksheet row at a later stage in the multipage userform, and looking up the data ta later date and enable editing
The code for the first page of the userform Submit Command button is below:
Private Sub btnSetupSubmit_Click()
'Check for all required entries
If tboSetupUserName = "" Or cboSetupBrand.Value = "" _
Or tboSetupDate = "" Or cboSetupPageType.Value = "" Or tboSetupPageTitle = "" _
Or tboSetupPageURL = "" Or tboSetupObjective = "" Or tboSetupMethod = "" Then
'Notify user if entries are missing
MsgBox "You must complete all fields on this page", vbCritical, "hmmm, want to try that again?"
Me.tboSetupUserName.SetFocus
Exit Sub
Else
'rest of code
'write this page data to worksheet
Dim LastRow As Object
Set LastRow = Sheet1.Range("a104857").End(xlUp)
'generate and write UniqueID
LastRow.Offset(1, 0).Value = LastRow.Offset(0, 0).Value + 1
'write UniqueID to form
tboSetupUniqueID.Text = LastRow.Offset(1, 0).Value
'write rest of data to worksheet
LastRow.Offset(1, 1).Value = tboSetupUserName.Text
LastRow.Offset(1, 2).Value = cboSetupBrand.Text
LastRow.Offset(1, 3).Value = tboSetupDate.Text
LastRow.Offset(1, 4).Value = cboSetupPageType.Text
LastRow.Offset(1, 5).Value = tboSetupPageTitle.Text
LastRow.Offset(1, 6).Value = tboSetupPageURL.Text
LastRow.Offset(1, 7).Value = tboSetupObjective.Text
LastRow.Offset(1, 8).Value = tboSetupMethod.Text
'notification to user
MsgBox "Data written to Worksheet", vbInformation, "Congratulations!"
'write UniqueID to tboPreChangeUniqueID.Value
tboPreChangeUniqueID.Value = tboSetupUniqueID.Value
'lock data
tboSetupUserName.Locked = True
cboSetupBrand.Locked = True
tboSetupDate.Locked = True
cboSetupPageType.Locked = True
tboSetupPageTitle.Locked = True
tboSetupPageURL.Locked = True
tboSetupObjective.Locked = True
tboSetupMethod.Locked = True
tboPreChangeUniqueID.Locked = True
'make Pre-Change Data page accessible
MultiPage1.pagPreChangeData.Visible = True
'take user to Pre-Change Data page
MultiPage1.Value = 1
End If
End Sub
The second page in the userform is MultiPage1 and this also has text and combo boxes on it, and when users input data into these boxes I need it to appear on the same row as specified by the uniqueID (tboSetupUniqueID.Value)
Hope someone can help
Thanks,
Ben