Problem with Userfom Values :(

d34n0

Board Regular
Joined
Jun 28, 2004
Messages
121
Good Morning all,

I have a set of userform controls that store their values on a worksheet so when the workbook is saved and re opened the userform controls retain the values from when they were last used by.

I have for example a set of controls for recording a person’s contact details (name tel, email etc). The name field is a combobox and the telephone and email fields are textbox types. The system works fine where I just type all the information in but I was trying to be clever and introduce a lookup table for the name field. If the name is already in the database the rest of the information will populate itself. This also works fine but for the following problem...

Where the person’s name is in the database but the email address is wrong the userform populates itself when I choose the person’s name from the combobox but obviously the email address field is wrong. When I change the email address the change is recorded on the worksheet that saves the information but when the workbook is closed and re opened the userform changes the email address again to the email on the database during the userform initialise process.


Private Sub UserForm_Initialize()
cboCustNam.Value = Sheets("Data").Range("D9").Value
txtCustTel.Value = Sheets("Data").Range("D10").Value
txtCustMob.Value = Sheets("Data").Range("D11").Value
txtCustEmail.Value = Sheets("Data").Range("D12").Value
End Sub


Private Sub cboCustSecContNam_Change()
Dim CSName As String
Dim CSTel As String
Dim CSMob As String
Dim CSEml As String
On Error Resume Next
CSName = cboCustSecContNam.Value
CSTel = Application.WorksheetFunction.VLookup(CSName, Sheets("Contacts").Range("A2:E25"), 3, 0)
CSMob = Application.WorksheetFunction.VLookup(CSName, Sheets("Contacts").Range("A2:E25"), 4, 0)
CSEml = Application.WorksheetFunction.VLookup(CSName, Sheets("Contacts").Range("A2:E25"), 5, 0)

Sheets("Data").Range("D9").Value = CSName
Sheets("Data").Range("D10").Value = CSTel
Sheets("Data").Range("D11").Value = CSMob
Sheets("Data").Range("D12").Value = CSEml
txtCustSecContTel.Value = CSTel
txtCustSecContMob.Value = CSMob
txtCustSecContEmail.Value = CSEml
On Error GoTo 0
End Sub

Problem seems to be that when the userform is initialised and the values on the spreadsheet are given to the text and combo boxes this triggers them to carry out the code associated with a change and then the loop begins.

Any ideas how I can overcome this?

Many Thanks
D34no
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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