fernando.rosales
Registered User.
- Local time
- Today, 04:40
- Joined
- Jun 11, 2014
- Messages
- 27
Hi All,
I am having trouble finding a solution to my problem on the internet.
I need help moving all the data from the recordset to a table. I am good looping if it cant be done with with one command just keep in mind there are multiple columns and rows in my recordset.
I also already have a local table that I want to move it into but if its easier to create a table I can work with that.
I am having trouble finding a solution to my problem on the internet.
I need help moving all the data from the recordset to a table. I am good looping if it cant be done with with one command just keep in mind there are multiple columns and rows in my recordset.
I also already have a local table that I want to move it into but if its easier to create a table I can work with that.
Code:
Function RDM_data_validation(poskustr2 As String)
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rcs As ADODB.Recordset
Dim stSQL As String
Dim str As String
DoCmd.RunSQL "delete * from tbl_RDM_Validation"
'Create a Connection
Set conn = New ADODB.Connection
With conn
.ConnectionString = "driver={sql Server}; server=SESQLPRD01; uid=NDSUSER;pwd=XXXX;database=XXXX "
.Open
End With
'Set Command to validate
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = conn
.CommandText = "SELECT * FROM OPENQUERY(SWDC, 'Select hw.company,hw.dc_id,hw.po_nbr,substr(hw.item_id,1,12) as item_id,hw.product_type_desc Product_Type,d.dept_desc Product_Group_Name " & _
",c.buyer_code,ia.comp_price,im.retail_price,hw.budget_yyyy,Case when hw.Budget_mm = 1 then ''FEB'' when hw.Budget_mm = 2 then ''MAR'' when hw.Budget_mm = 3 then ''APR'' when hw.Budget_mm = 4 then ''MAY'' " & _
"when hw.Budget_mm = 5 then ''JUN'' when hw.Budget_mm = 6 then ''JUL'' when hw.Budget_mm = 7 then ''AUG'' when hw.Budget_mm = 8 then ''SEP'' when hw.Budget_mm = 9 then ''OCT'' when hw.Budget_mm = 10 then ''NOV'' " & _
"when hw.Budget_mm = 11 then ''DEC'' when hw.Budget_mm = 12 then ''JAN'' Else ''Other'' end Budget_Month ,hw.budget_mm,hw.wip_codes,sum(hw.num_lpn) Num_Carton,sum(hw.unit_qty) Units " & _
"from ross_report_hotel_mlp hw, department d, class c, item_attribute ia, item_master im where hw.facility_id =''PR'' and concat(hw.po_nbr, substr(hw.item_id,1,12)) in (" & poskustr2 & ") " & _
"and hw.wip_codes =''HTRMK'' and hw.department = d.department and concat(hw.department, hw.class) = concat(c.department, c.class) and hw.item_id = ia.item_id and hw.item_id = im.item_id " & _
"Group by hw.company,hw.dc_id,hw.po_nbr,substr(hw.item_id,1,12),hw.product_type_desc,d.dept_desc,c.buyer_code,ia.comp_price,im.retail_price,hw.budget_yyyy,hw.Budget_mm ,hw.wip_codes Order by hw.Budget_mm asc')"
End With
Set rcs = cmd.Execute
If rcs.EOF Then
'Do nothing if no data returns. This is handled outside... after this function ends.
Else
rcs.MoveFirst
Do Until rcs.EOF = True
'At this point I can see the data but not helpful storing in variables, i need to move all to a table
sunits = rcs!units
'Other fields ....
rcs.MoveNext
Loop
End If
conn.Close
Set cmd = Nothing
Set conn = Nothing
Set rcs = Nothing
End Function