Edit for an existing working code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,232
Office Version
  1. 2007
Platform
  1. Windows
Morning,

Please can you advise how i can do the following.

I have a worksheet where when i double click the customers name in column A that then selected customer is shown in my database
Here is the code.

Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then Exit Sub
    Cancel = True
    Database.LoadData Me, Target.Row
End Sub

Now on a userform i search for customers.
The results are then shown in ListBox1.
I select the customer in ListBox1 then press a commandbutton.
The userform closes & that customer is then selected on my worksheet.
Here is the code

Rich (BB code):
Private Sub GoToCustomerVehicle_Click()
  Dim answer As Integer
  With ListBoxSearch
  Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 2)).Select
  Unload FindAndReplaceDatabase
End With
End Sub

I wish to add/edit the code in RED above so that customer is then open in my database as opposed to just being selected on my worksheet as it currently does.

OR

Just open that customer in the database directly from my userform without the need to select them on the worksheet first

Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Just an update but still not there.

I have the following code now.

Rich (BB code):
Private Sub CommandButton1_Click()
  Dim answer As Integer
  With ListBoxSearch
  Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 2)).Select
  Unload FindAndReplaceDatabase
  With ActiveCell
  Database.Show
End With
End With
End Sub

The code above now opens the userform in question BUT the customer shown isnt that of the selected customer on my worksheet.

I thought the code in Red would help but does nothing.
So to recap the customer is selected in the ListBox.
The customer is then selected on my worksheet.
NOW i need this customer loaded into the opening userform.
This is the part im stuck with


Please advise
 
Upvote 0
ListBoxSearch.List(ListBoxSearch.ListIndex, 2)
In column 2 of the ListBoxSearch you have the row number that corresponds to the customer selected in the listbox?

You could put here the code to load the ListBoxSearch.

Also put here the code of the Initialize and Activate event of the Database Userform
 
Upvote 0
Can we just open userform once customer is selected on worksheet.
I can then follow that way
 
Upvote 0
I am not quite understanding.
If you already have the customer's row selected. I guess in the form you can do something like:
textbox1.value = range ("A" & activecell.row)
 
Upvote 0
Im confused.

i dont follow the partial code you wrote or where to place it.

Can we do it this way.

Rich (BB code):
Private Sub CommandButton1_Click()
  Dim answer As Integer
  With ListBoxSearch
  Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 2)).Select
  Unload FindAndReplaceDatabase
End With
End Sub

This selects the customer on my worksheet.
I now need to open the userform called DATABASE & have this customer pre loaded
 
Upvote 0
This selects the customer on my worksheet.

After closing the FindAndReplaceDatabase form you open the Database form:
VBA Code:
Private Sub CommandButton1_Click()
  Dim answer As Integer
  With ListBoxSearch
    Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 2)).Select
    Unload FindAndReplaceDatabase
    Database.Show
  End With
End Sub


Now, in the code of the Database form in the Activate event you must put the following code:
I do not know the controls that you have in the Database form, I am putting 2 examples of 2 textbox and assuming that they correspond to columns A and B

VBA Code:
Private Sub UserForm_Activate()
  TextBox1.Value = Range("A" & ActiveCell.Row)
  TextBox2.Value = Range("B" & ActiveCell.Row)
  '
  'Continue with your other controls
End Sub
 
Upvote 0
Thanks for your time but its not working for me & im spending time trying now to work out why.
Im unable to do it so will just delete this project.

Thanks
 
Upvote 0
You could upload a copy of your file to a free site such www.dropbox.com or google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

It would be my pleasure to help you adapt the code.
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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