Select customer on worksheet to then open in main database

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
My database values start at row 6.
Customers names are in column A

I would like to select a customer then press the command button to open the customers details in my main database.

This is what i have but get a message saying Object Required

Rich (BB code):
Private Sub OpenCustomerInDatabase_Click()
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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
First of all I think you needed something like this. Target only works when you have a Worksheet event. I think your target is the row your cursor is on, correct?

VBA Code:
If Intersect(Range(Range("A6"), Cells(Rows.Count, "A").End(xlUp)), ActiveCell.EntireRow) Is Nothing Then Exit Sub
 
Upvote 0
Hi,
Unable to check until tomorrow.

My target is whichever cell has been selected in column A

Does that help.
 
Upvote 0
My target is whichever cell has been selected in column A

Does that help.
I think you are mixing up Event Procedure VBA code with what you are trying to do here (which is NOT Event Procedure VBA code).

What you said is only true for Event Procedure code that has the Target argument as one of the inputs, i.e.
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    ...
End Sub

"Target" is not defined anywhere in your code, and therefore isn't anything.
If you want the selected cell, use "ActiveCell" instead.
 
Upvote 0
Solution
This now worked for me thanks,


Private Sub OpenCustomerInDatabase_Click()
If Intersect(Range("A6", Cells(Rows.Count, "A").End(xlUp)), ActiveCell) Is Nothing Then Exit Sub

Cancel = True

Database.LoadData Me, ActiveCell.Row
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,131
Members
449,097
Latest member
mlckr

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