Database Output

Perch1224

New Member
Joined
Jul 1, 2004
Messages
11
Ok here is my question. Right now I am pulling data from a database through excel. I have been able to specifically choose what information i want to bring out of the database while running queries through VBA. My question is how can I get it to show the out put of a column of numbers. I want to be able to tell it where to start pulling the information from and when to stop pulling it. Here is the code I have so far that pull out specific information.

Code:
Private Sub CommandButton1_Click()

'Defining variables
Dim cnOra As ADODB.Connection
Dim rsOra As ADODB.Recordset
Dim db_name As String
Dim UserName As String
Dim Password As String
Dim varInput As String  'variable for first input box
Dim varInput2 As String 'variable for second input box
Dim in3 As Integer 'variable for third input box
Dim in4 As Integer 'variable for fourth input box

Set cnOra = New ADODB.Connection
Set rsOra = New ADODB.Recordset

db_name = "AS"
UserName = "Test"
Password = "Entry"

'Making an ODBC connection according to ADO
cnOra.Open "DSN=" + db_name + ";UID=" + UserName + ";PWD=" _
& Password + ";"
rsOra.CursorLocation = adUseServer



'Running a query
rsOra.Open "select * from APLUS.SUM where Year=2004 and Accnm= 1855", cnOra, adOpenForwardOnly

'Passing on data from the recordset to a variable or cell.
'Notice that the column name or alias is used to address
'data in the recordset.

in3 = 1
in4 = 1
Worksheets("Sheet1").Activate
While Not rsOra.EOF
   
    ActiveSheet.Cells(in4, in3) = CStr(rsOra![GSDR09])
   
    rsOra.MoveNext
    
Wend


rsOra.Close
cnOra.Close
Set rsOra = Nothing

End Sub

Any help would be greatly appreciated.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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