Solved

Next and Previous buttons

Posted on 2016-11-04
9
59 Views
Last Modified: 2016-11-04
Hi , How do I get this code for previous row entry to work and display in the text boxes.  This code is not working and obviously the reverse of this will be the next button. But until this works I cant get the NEXT button to work.  

Private Sub Cmdbutton_PREVIOUS_Click()

   Dim ws As Worksheet
Set ws = Worksheets("Blueteq")

Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1

CurrentRow = CurrentRow - 1
If CurrentRow > 1 Then

 
 TextBox_Initials = Cells(CurrentRow, 1)
 TextBox_HNUMBER = Cells(CurrentRow, 2)
DTPicker_DOB = Cells(CurrentRow, 3)
TextBox_NHSNUMBER = Cells(CurrentRow, 4)
TextBox_GPNUMBER = Cells(CurrentRow, 5)
ComboBox_DRUG = Cells(CurrentRow, 6)
ComboBox_INDICATION = Cells(CurrentRow, 7)
DTPicker_STARTDATE = Cells(CurrentRow, 8)
TextBox_CONSULTANT = Cells(CurrentRow, 9)
Me.DTPicker_DATEADDED = Cells(CurrentRow, 10)
 ComboBox_Blueteqdrug = Cells(CurrentRow, 11)
 ComboBox_FORMLIST = Cells(CurrentRow, 12)
TextBox_BLUETEQID = Cells(CurrentRow, 15)
 DTPicker_APPROVALDATE = Cells(CurrentRow, 16)
TextBox_DOCTOR = Cells(CurrentRow, 17)
ComboBox_STATUS = Cells(CurrentRow, 18)
TextBox_EMAIL = Cells(CurrentRow, 19)
TextBox_Commisioners = Cells(CurrentRow, 20)

End If
If CurrentRow = 1 Then


CurrentRow = CurrentRow + 1
 End If
End Sub
0
Comment
Question by:Sam Coombes
  • 5
  • 4
9 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41873728
How about a sample sheet for testing?
0
 

Author Comment

by:Sam Coombes
ID: 41873773
Hi , Here is the spreadsheet

Thank You so much
Blueteqv4-email-v1.xlsm
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 41873830
Replace the above code with
Private Sub Cmdbutton_PREVIOUS_Click()

Dim ws As Worksheet
Set ws = Worksheets("Blueteq")

Dim newRow As Long
'newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
currentrow = ActiveCell.Row - 1
If currentrow < 7 Then
    currentrow = 7
End If
ws.Cells(currentrow, 1).EntireRow.Select
loadrowtoform (currentrow)
End Sub

Sub loadrowtoform(currentrow)
    TextBox_Initials = Cells(currentrow, 1)
    TextBox_HNUMBER = Cells(currentrow, 2)
    DTPicker_DOB = Cells(currentrow, 3)
    TextBox_NHSNUMBER = Cells(currentrow, 4)
    TextBox_GPNUMBER = Cells(currentrow, 5)
    ComboBox_DRUG = Cells(currentrow, 6)
    ComboBox_INDICATION = Cells(currentrow, 7)
    DTPicker_STARTDATE = Cells(currentrow, 8)
    TextBox_CONSULTANT = Cells(currentrow, 9)
    Me.DTPicker_DATEADDED = Cells(currentrow, 10)
    ComboBox_Blueteqdrug = Cells(currentrow, 11)
    ComboBox_FORMLIST = Cells(currentrow, 12)
    TextBox_BLUETEQID = Cells(currentrow, 15)
    DTPicker_APPROVALDATE = Cells(currentrow, 16)
    TextBox_DOCTOR = Cells(currentrow, 17)
    ComboBox_STATUS = Cells(currentrow, 18)
    TextBox_EMAIL = Cells(currentrow, 19)
    TextBox_Commisioners = Cells(currentrow, 20)

End Sub

Private Sub UserForm_Activate()
currentrow = ActiveCell.Row
If currentrow < 7 Then
    currentrow = 7
End If
Cells(currentrow, 1).EntireRow.Select
loadrowtoform (currentrow)

End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 500 total points
ID: 41873833
When you load the form the current row would be displayed
0
 

Author Comment

by:Sam Coombes
ID: 41873872
That's works amazing but why doesn't  the add button work after you press the previous button
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41873874
I did not work on any thing else. What is the add button supposed to do?
0
 

Author Closing Comment

by:Sam Coombes
ID: 41873934
Thats fantastic works a treat, sorry I was just a little confused earlier but all fixed now
0
 

Author Comment

by:Sam Coombes
ID: 41874338
Hi , Once again thank you so much but now do you have any idea how to get an upate/edit button to work
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41874598
You need to explain what you want it to do.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question