简体   繁体   中英

Having a multipage userform submit information each time it moves to the next page

I have a 3-page userform that I'm working on, and at the bottom of the first two pages, there's a "next" button which has a validation for the input of the fields on that page, and then increments the multipage.value by one (moving to the next page).

eg.

Private Sub NextButton1_Click()

'check for a Name 
If TextBox1_First.Text = "" Then
    MsgBox "Please enter your first name"
    Exit Sub
End If

`check for a last name
If TextBox2_Last.Text = "" Then
    MsgBox "Please enter your last name"
    Exit Sub
End If

`check for a phone number   
If TextBox4_Phone.Text = "" Then
    MsgBox "Please enter your phone number"
    Exit Sub
End If

`check for valid email
If InStr(TextBox3_Email.Text, "@") = 0 Or InStr(TextBox3_Email.Text, ".") = 0 Then
    MsgBox "Please enter your complete email address"
    Exit Sub
End If

MultiPage1.Value = MultiPage1.Value + 1

End Sub

is it possible for that "next" button to also input the information on the active page, then move to the next one while "remembering" which row it's in? seems like there'd be no way to use the "find next blank row" code that I have for the regular submit button since I don't know how to stay in that row when I move to the next page.

basically, how would I add data from the active page to a new row, then add data from subsequent pages to the same row up to the last provisioned cell?

EDIT: figured it out! this is the code I was using to initialize my data input

Private Sub CommandButton_Submit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Customer Information")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

and then a bunch of "ws.Cells().Value" lines for each field. what I realized was that I could just remove the "+ 1" for each subsequent use of that code and just stay on the same line!!

Private Sub CommandButton_Next_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Customer Information")

'find current row
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row 

I just sort of had an epiphany early this morning when I was thinking about it over breakfast, and realized it was just an incredibly simple/obvious solution, but I hadn't even thought about it.... :(

Hope this helps anyone else who comes across it!

EDIT: figured it out! this is the code I was using to initialize my data input

Private Sub CommandButton_Submit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Customer Information")

'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

and then a bunch of "ws.Cells().Value" lines for each field. what I realized was that I could just remove the "+ 1" for each subsequent use of that code and just stay on the same line!!

Private Sub CommandButton_Next_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Customer Information")

'find current row
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row 

I just sort of had an epiphany early this morning when I was thinking about it over breakfast, and realized it was just an incredibly simple/obvious solution, but I hadn't even thought about it.... :(

Hope this helps anyone else who comes across it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM