interactive userform (read/write)

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I want to learn how to make simple interactive form like the one below which can upload data from excel sheet to the form if user entered an existing ID# or if the ID is not existed then that would be a new record to be added to the form. ExcelEasy website has the code but I have found it very difficult to follow. I wonder if there is a simpler code that I can read to understand the idea and how it can be done?
Would appreciate any help very much. Thanks you

https://www.excel-easy.com/vba/examples/interactive-userform.html

interactive-userform-1.png
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Let me see if I understand

Your wanting to load data into the Userform

So in this example when you enter a value into the Textbox Named Id you want the Name and City loaded into the Userform Textboxes

Now I do not under your other question where you say:

or if the ID is not existed then that would be a new record to be added to the form

We do not add records to a Userform. A record refers to a row of data on a Sheet.

If there is no record we cannot load it's values into the Userform
Or do you mean take the values from a Userform and create a new record on the sheet.
Record is a sheet row.


So do you want to start by loading values into the userform?

Now after you load values into the userform what do you plan to do next?

 
Upvote 0
Thanks a lot for your reply. Sorry I was not clear.
I wrote an explanation using my own words but then after reading it, I found it not that clear. So I went to the website and copied exactly what this form suppose to do which is better explaintion than mine. Thank you very much once again. Here is the explanation

"Explanation: whenever you enter a value in the ID text box, Excel VBA loads the corresponding record. When you click the Edit / Add button, Excel VBA edits the record on the sheet or adds the record when the ID does not yet exist"
 
Upvote 0
I'm not really interested in what the wed site says.

I want to know what you want.

What do you want?
 
Upvote 0
Ok thanks. If the user entered ID# and if this ID existed in the sheet, then excel will put other values from the sheet to the form for example Name and the City. Then user might change the city name for example and hit Edit/Add button then that row will be updated accordingly with these new values (in this case City name)

If the user entered ID which is not in the sheet, then Name and City boxes will stay empty. In this case if the user entered values in the Name and City boxes and hit Edit/Add then a new row will be created in the sheet with this ID, Name, and the City.

Thank you once again.
 
Upvote 0
If you have a textbox on your userform named id
And a Textbox named MyName and a Textbox Named City

And you put this script in a command button on your userform

This script will look down column A of the active sheet for the id number entered in id textbox

If found the name in column B and the city in column C will be loaded in the textbox named MyName and City

Now what you plan to do next is not clear.

Code:
Private Sub CommandButton3_Click()
'Modified  11/28/2018  7:56:08 PM  EST
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim ans As String
ans = id.Value
Set SearchRange = Range("A1:A" & Lastrow).Find(ans)
If SearchRange Is Nothing Then MsgBox ans & "  Not Found": Exit Sub
MyName.Value = SearchRange.Offset(, 1).Value
City.Value = SearchRange.Offset(, 2).Value
End Sub
 
Upvote 0
I now see your last post.
Try my script to see if it does the first part you want.
And this assumes all your data is on the active sheet.
 
Upvote 0
The code above works very well. Thank you. Yes that is the first part is exactly what I expected. Wow your code is so easy to understand. Thank you once again.
 
Upvote 0
So now you want to modify the name or city and the reload those values back into the sheet is that correct?
 
Upvote 0

Forum statistics

Threads
1,223,659
Messages
6,173,636
Members
452,525
Latest member
DPOLKADOT

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