Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > PC based Database Applications > Microsoft Excel > Using ComboBox to feed into another function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-08, 09:14
JezLisle JezLisle is offline
Registered User
 
Join Date: Apr 2007
Location: Stalybridge, Manchester
Posts: 240
Using ComboBox to feed into another function

How is it possible to take the choice from the Combo Box and send that into a Stored Procedure statement in Excel VBA

I have 3 Combo Boxes, Months, Years, Date.

I'm trying to fillout these into this statement to run my Stored Procedure...

Code:
EXEC sp_WLName_Report 'September', '2008', " & _ "'18-09-2008', 'C2PD'

This is my full code that brings back the results

Code:
Option Explicit Dim cnnDW As ADODB.Connection Dim rsDW As ADODB.Recordset Dim cmdSP As ADODB.Command Dim strDWFilePath As String Dim stProcName As String Sub GetData() On Error GoTo Err: '------------------------------------------------------------------------------------------------------------------------------------------------- 'Connects to CISSQL on SQL Server and Database CORPINFO, uses the connection of the network Username & 'Password for the user edditing this report. strDWFilePath = "Driver={SQL Native Client};" & _ "Server=CISSQL1;" & _ "Database=CORPINFO;" & _ "Trusted_Connection=Yes" Set cnnDW = New ADODB.Connection '------------------------------------------------------------------------------------------------------------------------------------------------- Application.ScreenUpdating = False cnnDW.Open strDWFilePath Set rsDW = New ADODB.Recordset '------------------------------------------------------------------------------------------------------------------------------------------------- 'Define name of Stored Procedure to execute stProcName = "EXEC sp_WLName_Report 'September', '2008', " & _ "'18-09-2008', 'C2PD'" '------------------------------------------------------------------------------------------------------------------------------------------------- Sheet1.Range("E4:F9").ClearContents rsDW.CursorLocation = adUseClient rsDW.Open stProcName, cnnDW, adOpenDynamic, adLockOptimistic, adCmdText Application.ScreenUpdating = False Sheet1.Range("E4").CopyFromRecordset rsDW rsDW.Close Set rsDW = Nothing '------------------------------------------------------------------------------------------------------------------------------------------------- MsgBox "Import Complete", vbInformation, "SQL Connection" cnnDW.Close Set cnnDW = Nothing Exit Sub '------------------------------------------------------------------------------------------------------------------------------------------------- Err: MsgBox "The following error has occured-" & vbCrLf & vbCrLf & VBA.Error, vbCritical, "SQL Connection" MsgBox VBA.Err End Sub

How is it possible to do this?
Reply With Quote
  #2 (permalink)  
Old 09-25-08, 10:03
Wim Venema Wim Venema is offline
Registered User
 
Join Date: Jun 2004
Location: Lichtenvoorde, Netherlands
Posts: 35
I think you can use:
stProcName = "EXEC sp_WLName_Report sheet1.combobox1.value, sheet1.combobox2.value, " & _
"sheet1.combobox3.value, 'C2PD'"
supposing that the controls are on sheet1 and have the default names...
Reply With Quote
Reply


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

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