Edit for an existing working code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
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
 
Ok Thanks.

Here is the file.
Please then do the following.

Excel file


Open worksheet.
Top left select OPEN LINKS PAGE.
Select FIND AND REPLACE ON DATABASE
Click the yellow box below Vehicle.
Type YAM
Select the result TEST 001
Select the grey command button button of form.
Now in column A you will see TEST 001 is selected.

It is this that should be opened in the DATABASE userform.

To get to see what it looks like DOUBLE CLICK TEST 001

Many Thanks
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The following line must go to the beginning of all the code of the userform FindAndReplaceDatabase
VBA Code:
Public callDatabase As Boolean

Code for CommandButton1 of the userform FindAndReplaceDatabase
VBA Code:
Private Sub CommandButton1_Click()
  Dim answer As Integer
  With ListBoxSearch
    Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 2)).Select
    callDatabase = True
    Database.Show
  End With
End Sub


Code for event Initialize of the userform Database
VBA Code:
Private Sub UserForm_Initialize()
    Set ws = ThisWorkbook.Worksheets("Database")
    ComboBoxCustomersNames_Update

    If FindAndReplaceDatabase.callDatabase = True Then
      r = ActiveCell.Row - 1
      Unload FindAndReplaceDatabase
    Else
      r = 0
    End If
    ResetButtons False
    'start at first record
    Navigate Direction:=xlFirst
    txtCustomer.SetFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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