Display information in second form

JessyVal

New Member
Joined
Feb 23, 2021
Messages
30
Office Version
  1. 365
Hi, me again, Sorry for ask many question, I am new in vba excel.

I have a form, this form allows you to look for a person (probably I have many people named David), in case you have many registers with one name (but different last name) you can pick wich register you want to update.

1618934084685.png


once you select a person , a new form is displayed

1618934129415.png


what I want to do is, once you select the person in the first form, and click in Modify, i would like to be able to see the information of that particular person displayed in this second form, and will be able to edit it.

Now, the code that I have in the second form is

VBA Code:
Private Sub btnEdit_Click()

Dim vol_name As String
vol_name = Trim(txtbox.Text)

lastRow = Worksheets("Registers").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastRow


    If Worksheets("Registers").Cells(i, 2).Value = vol_id Or Worksheets("Registers").Cells(i, 3).Value = vol_name Then
    
    answer = MsgBox("Are you sure you want to update the record?", vbYesNo + Question, "Update Record")
    If answer = vbYes Then
    
    Worksheets("Registers").Cells(i, 3).Value = txtvolName.Text
    Worksheets("Registers").Cells(i, 4).Value = txtvolLastName.Text
    Worksheets("Registers").Cells(i, 5).Value = txtvolEmail.Text
    Worksheets("Registers").Cells(i, 6).Value = txtvolAddress.Text
    Worksheets("Registers").Cells(i, 7).Value = txtcity.Text
    Worksheets("Registers").Cells(i, 8).Value = txtcounty.Text
    Worksheets("Registers").Cells(i, 9).Value = txteircode.Text
    Worksheets("Registers").Cells(i, 10).Value = txtphone.Text
    Worksheets("Registers").Cells(i, 11).Value = txttwitter.Text
    Worksheets("Registers").Cells(i, 12).Value = schedule_list.Text
    Worksheets("Registers").Cells(i, 13).Value = txtgarda.Text
    Worksheets("Registers").Cells(i, 14).Value = help_list.Text
    Worksheets("Registers").Cells(i, 15).Value = txtzendesk.Text
    Worksheets("Registers").Cells(i, 16).Value = txtmicro_365.Text
    
    MsgBox "The record is updated"
    Exit Sub
    
    Else
    MsgBox "The record is not going to be updated"
    Exit Sub
    
    End If
    
    End If


 Next

Unload Me
End Sub


Private Sub UserForm_Initialize()
frmUpdateVolunteer.Show

For i = 1 To 3
    Me.Controls("Textbox" & i).Value = ActiveCell.Offset(0, i - 1).Value
Next i

End Sub


Thank you
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
this is a good example of why i do not rename controls to "meaningful" names as you have done with your textboxes. whilst it is a good practice with variables, if you leave them as generic "TextBox1" etc you can do this:

VBA Code:
Sub SaveYourData
    For Col=1 to 10
        Cells(MyRecord, Col) = Controls("TextBox" & Col).Text
    Next Col
End Sub

Sub ReadYourData
    For Col=1 to 10
        Controls("TextBox" & Col).Text = Cells(MyRecord, Col)
    Next Col
End Sub
 
Upvote 0
this is a good example of why i do not rename controls to "meaningful" names as you have done with your textboxes. whilst it is a good practice with variables, if you leave them as generic "TextBox1" etc you can do this:

VBA Code:
Sub SaveYourData
    For Col=1 to 10
        Cells(MyRecord, Col) = Controls("TextBox" & Col).Text
    Next Col
End Sub

Sub ReadYourData
    For Col=1 to 10
        Controls("TextBox" & Col).Text = Cells(MyRecord, Col)
    Next Col
End Sub
Hi thank you so much for your answer, i made the changes but still not working,
 
Upvote 0
Hi,
helpful to forum if you could place copy of your workbook with dummy data on a filesharing site like dropbox.

Dave
 
Upvote 0
thanks - will take a look when can

Dave
 
Upvote 0
Hi,
give this update to your project a try & see if now does what you want


I have added a single search box to the form where you can search for ID, Name or Last Name. Entering a partial search text & pressing the search button displays the search form with matching entries displayed in listbox.
You can further refine the search by changing the value shown in the textbox.
Selecting the required record from the listbox & pressing the modify button should display the record in the main form where you can edit or delete the record.

Hope Helpful

Dave
 
Upvote 0
Hi,
give this update to your project a try & see if now does what you want


I have added a single search box to the form where you can search for ID, Name or Last Name. Entering a partial search text & pressing the search button displays the search form with matching entries displayed in listbox.
You can further refine the search by changing the value shown in the textbox.
Selecting the required record from the listbox & pressing the modify button should display the record in the main form where you can edit or delete the record.

Hope Helpful

Dave
Hi Dave, sorry for the late replay
thank you so much for your answer, but I can't visualise the file.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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