If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > using excel range as sql parameter in vba macro

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-02-12, 08:01
cairnsroo cairnsroo is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
Red face using excel range as sql parameter in vba macro

Hello

I'm a newbe, so please bear with me.

I'm having problems doing the following in VBA for Excel

A first piece of VBA script in an active Excel worksheet accesses an external DB and fills columns E from row 10 onwards with social security numbers. So far so good

A second piece of VBA script is supposed to get the first entry in the social security column (>E10) and use that value in a VBA macro that contains a sql command. The aim is for SQL to get to a second external DB and extract name and address for the person belonging to the social security number.
Name and number are to be put in column C and D of the same row the social security number was taken from.

Then the VBA script is to proceed to the next row in column E and do it all over again for the second social security number. And so on until there are no more numbers in column E.

If I put the social security number in the SQL string as an exact numerical value (like 1234567) it works. I don't now how to refer to sucessive rows in column E however.

Some stuff I'm using

Dim client As String
Dim Name As String

Const column_Client As String = "C"
Const Column_Name As String = "D"

' Column E is define as follows
Dim RgSocialSec As Range

Set RgSocialSec = Range("E10:E3000").Select


Really stuck with this
Many thanks for any help
Reply With Quote
  #2 (permalink)  
Old 01-02-12, 08:07
cairnsroo cairnsroo is offline
Registered User
 
Join Date: Jan 2012
Posts: 2
refering to excel rang as sql parameter in VBA

Hello

I'm a newbe, so please bear with me.

I'm having problems doing the following in VBA for Excel

A first piece of VBA script in an active Excel worksheet accesses an external DB and fills columns E from row 10 onwards with social security numbers. So far so good

A second piece of VBA script is supposed to get the first entry in the social security column (>E10) and use that value in a VBA macro that contains a sql command. The aim is for SQL to get to a second external DB and extract name and address for the person belonging to the social security number.
Name and number are to be put in column C and D of the same row the social security number was taken from.

Then the VBA script is to proceed to the next row in column E and do it all over again for the second social security number. And so on until there are no more numbers in column E.

If I put the social security number in the SQL string as an exact numerical value (like 1234567) it works. I don't now how to refer to sucessive rows in column E however.

Some stuff I'm using

Dim client As String
Dim Name As String

Const column_Client As String = "C"
Const Column_Name As String = "D"

' Column E is define as follows
Dim RgSocialSec As Range

Set RgSocialSec = Range("E10:E3000").Select


Really stuck with this
Many thanks for any help
Reply With Quote
Reply

Tags
excel, range, sql, variable, vba

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On