So I was wondering if someone here could help me edit some VBA code for access.
Here is the code:
I am specifically having trouble with this in the code: & Replace(sTable, "[_NEW SF 133]", "") & "' AS TS "
It is returning my TS like this:
Excel 2012
<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]4[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS[/TD]
[TD="bgcolor: #C0C0C0, align: center"]SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS_SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineAmt[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineDescription[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]1000[/TD]
[TD="align: right"]$1,000,000.00[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"]1021[/TD]
[TD="align: right"]$1,000,000.00[/TD]
</tbody>
When I really need it to show up like this: (without the _NEW SF 133)
Excel 2012
<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]4[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS[/TD]
[TD="bgcolor: #C0C0C0, align: center"]SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS_SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineAmt[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineDescription[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]1000[/TD]
[TD="align: right"]$1,000,000.00[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"]1021[/TD]
[TD="align: right"]$1,000,000.00[/TD]
</tbody>
Can anyone help me edit the replace function with something that will give me the TS only?
Thanks,
Amanda
Here is the code:
Code:
Public Function GTAS()
Dim SBRLink2017 As DAO.Database
Set SBRLink2017 = CurrentDb
Dim delSQL As String
Dim updSQL As String
'Dim LinSQL As String
DoCmd.SetWarnings False
delSQL = "DELETE tbl_GTAS.* FROM tbl_GTAS';"
DoCmd.RunSQL (delSQL)
Dim tdf As DAO.TableDef
Set db = CurrentDb
For Each tdf In db.TableDefs
' ignore system and temporary tables
If Not (tdf.Name Like "MSys*" Or tdf.Name Like "~*") Then
Dim sTable As String
sTable = tdf.Name
Dim strSQL
strSQL = "INSERT INTO Tbl_GTAS ( SF133_Rpt_Line, LineDescription, LineAmt, TS)" & _
" SELECT T.F1, T.F2, T.F3, '" [B]& Replace(sTable, "[_NEW SF 133]", "") & "' AS TS "[/B] & _
"FROM [" & sTable & "] AS T " & _
"GROUP BY T.F1, T.F2, T.F3,'" & Replace(sTable, "[_NEW SF 133]", "") & "';"
Debug.Print strSQL
'do what you will with SQL
DoCmd.RunSQL strSQL
End If
Next
updSQL = "UPDATE Tbl_GTAS SET Tbl_GTAS.TS_SF133_Rpt_Line = [TS] & '_' & [SF133_Rpt_Line];"
DoCmd.RunSQL (updSQL)
'LinSQL = "DELETE Tbl_GTAS.LineAmt FROM Tbl_GTAS WHERE Tbl_GTAS.LineAmt Is Null OR Tbl_GTAS.LineAmt<0.001 And Tbl_GTAS.LineAmt>-0.001';"
'DoCmd.RunSQL (LinSQL)
DoCmd.SetWarnings True
MsgBox ("The procedure is complete")
End Function
I am specifically having trouble with this in the code: & Replace(sTable, "[_NEW SF 133]", "") & "' AS TS "
It is returning my TS like this:
Excel 2012
A | B | C | D | E | |
---|---|---|---|---|---|
75-1012-0943_NEW SF 133 | 75-1012-0943_NEW SF 133_1000 | Description | |||
75-1012-0943_NEW SF 133 | 75-1012-0943_NEW SF 133_1021 | Description |
<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]4[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS[/TD]
[TD="bgcolor: #C0C0C0, align: center"]SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS_SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineAmt[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineDescription[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]1000[/TD]
[TD="align: right"]$1,000,000.00[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"]1021[/TD]
[TD="align: right"]$1,000,000.00[/TD]
</tbody>
Data
When I really need it to show up like this: (without the _NEW SF 133)
Excel 2012
A | B | C | D | E | |
---|---|---|---|---|---|
75-1012-0943 | 75-1012-0943_1000 | Description | |||
75-1012-0943 | 75-1012-0943_1021 | Description |
<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]4[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS[/TD]
[TD="bgcolor: #C0C0C0, align: center"]SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]TS_SF133_Rpt_Line[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineAmt[/TD]
[TD="bgcolor: #C0C0C0, align: center"]LineDescription[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]1000[/TD]
[TD="align: right"]$1,000,000.00[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"]1021[/TD]
[TD="align: right"]$1,000,000.00[/TD]
</tbody>
Data
Can anyone help me edit the replace function with something that will give me the TS only?
Thanks,
Amanda