userform code strange anomally

pwwato

New Member
Joined
Jun 10, 2017
Messages
40
Hi All

Thanks for taking the time to look at this and any help given is much appreciated.

I have a userform for contacts that contains various controls and a multipage with dynamically created pages referencing a site worksheet, on the userform there is a add lift button.

What I am trying to do is depending on which multipage page (sites) is selected when add lift is pressed then another userform called liftnewform is opened and various controls on this userform are filled in so the first part

ADD LIFT code is

Public Sub ADDLIFT_Click()
Dim sp As Double
Dim spname As String


If MultiPage2.Pages.Count = 1 Then
MsgBox "NO SITES SETUP FOR:-" & CONTACT.NAME1, vbOKOnly, "York Elevator Services Ltd"
Exit Sub
Else
If MultiPage2.Pages.Count >= 1 Then
sp = CONTACT.MultiPage2.Value
spname = CONTACT.MultiPage2.Pages(sp).NAME
LIFTNEWFORM.LSREF = spname
LIFTNEWFORM.Caption = CONTACT.NAME1
LIFTNEWFORM.Show
LIFTNEWFORM.LUPDATE.Visible = False
LIFTNEWFORM.LSAVE.Visible = True

End If
End If
End Sub

This loads the form and fills in the forms caption and site ref on the new lift form

THE FORMS INITIATE code is a find command to find the contact ref then check the next columns value and if it is the same as the site ref then enter the site name from same row using column offset

Dim liftref As String
Dim slastrow As String
Dim lastrow As String
'
Dim WHAT_TO_FIND As String
Dim ws As Excel.Worksheet
Dim FoundCell As Excel.Range
Dim R As Long
Dim SMSGVAL As String
Dim SMSGR As String
Dim sp As Double
Dim spname As String
Dim SCL As Range
Dim STRF As String
Application.ScreenUpdating = False
Application.Workbooks("yesdatav2.xlsm").Sheets(5).Activate
Application.Workbooks("yesdatav2.xlsm").Sheets("lifts").Select

With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).ROW
End With


If CONTACT.CINFO.Value = 1 Then
Application.Workbooks("yesdatav2.xlsm").Sheets(4).Activate
Application.Workbooks("yesdatav2.xlsm").Sheets("sites").Select


With ActiveSheet
slastrow = .Cells(.Rows.Count, "A").End(xlUp).ROW
End With

Set ws = Sheet4
WHAT_TO_FIND = CONTACT.REF.Value
Set FoundCell = ws.Range("A:A").Find(what:=WHAT_TO_FIND, lookat:=xlWhole)
If Not FoundCell Is Nothing Then Check contact ref for match in site sheet


SMSGVAL = CONTACT.REF
sp = CONTACT.MultiPage2.Value
spname = CONTACT.MultiPage2.Pages(sp).NAME

For Each SCL In Sheet4.Range("A1:A" & slastrow) Check all matched contact ref's next cell value against the active page name which is the site ref
If SCL.Value = SMSGVAL Then
SMSGR = SCL.Offset(, 1).Text

If SMSGR = spname Then
R = SCL.Offset.ROW
LIFTNEWFORM.LROW = lastrow
LIFTNEWFORM.SNAME.Value = SCL.Offset(, 3).Value

Exit Sub
Else
End If
Else
End If
Next SCL
Else
MsgBox "NO MATCHING SITE REF FOUND"
End If
Exit Sub

The problem I am having is on first click of add lift it works perfectly whichever page is selected. once liftnewform is closed and another page(site) on multipage is selected and add lift pressed again, it works but sname retains previous value if I close form and press add lift again it works correctly and sname has right value. It does this everytime I close and select a different page unless I restart the contacts form.

it is not a massive issue but very annoying as I cant seem to pin point the cause.

Thanks for any help given
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
.
Can you post a copy of your workbook to a download site like: DropBox or some other cloud service ? Makes it alot easier to understand and troubleshoot. Leave out any confidential
data.
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,536
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top