Option Compare Database
Option Explicit
Private Function Conversion()
Dim dbsOmya_2 As DAO.Database
Dim rstSAP_SALES1 As DAO.Recordset
Dim InStrB As String
Dim INCO_2X As String
Dim strSQL As String
Dim Count As Integer
Dim i As Integer
Dim value As String
Dim FIX_SC As String
On Error GoTo ErrorHandler
Set dbsOmya_2 = CurrentDb
'Open a recordset on all records from the rstSAP_SALES1 table that have
strSQL = "SELECT * FROM SAP_SALES1;"
Set rstSAP_SALES1 = dbsOmya_2.OpenRecordset(strSQL, dbOpenDynaset)
'If the recordset is empty, exit.
If rstSAP_SALES1.EOF Then Exit Function
Count = 1
With rstSAP_SALES1
Do Until rstSAP_SALES1.EOF
.Edit
' CONVERT SHIP_QTY TO rstSAP_SALES1![SALE_QTY] - DRY '
If rstSAP_SALES1![PKG_FORM] <> "01" Then
If rstSAP_SALES1![SU] = "TON" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY]
End If
If rstSAP_SALES1![SU] = "TO" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] * 1.1023
End If
If rstSAP_SALES1![SU] = "LB" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] / 2000
End If
If rstSAP_SALES1![SU] = "DTN" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY]
End If
If rstSAP_SALES1![SU] = "DLB" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] / 2000
End If
If rstSAP_SALES1![SU] = "DTO" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] * 1.1023
End If
If rstSAP_SALES1![SU] = "KG" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] / (2.2046 * 2000)
End If
End If
rstSAP_SALES1![SHIP_WGT_USTONS] = rstSAP_SALES1![SALE_QTY]
rstSAP_SALES1![SHIP_WGT_MTONS] = rstSAP_SALES1![SALE_QTY] / 1.1023
' CONVERT SALE_QTY TO rstSAP_SALES1![SALE_QTY] - SLURRY '
If rstSAP_SALES1![PKG_FORM] = "01" Then
If rstSAP_SALES1![SU] = "TON" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] * rstSAP_SALES1![SLURRYPC]
End If
If rstSAP_SALES1![SU] = "TO" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] * 1.1023 * rstSAP_SALES1![SLURRYPC]
End If
If rstSAP_SALES1![SU] = "LB" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] / 2000 * rstSAP_SALES1![SLURRYPC]
End If
If rstSAP_SALES1![SU] = "DTO" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] * 1.1023 * rstSAP_SALES1![SLURRYPC]
End If
If rstSAP_SALES1![SU] = "KG" Then
rstSAP_SALES1![SALE_QTY] = rstSAP_SALES1![SHIP_QTY] / (2.2046 * 2000) * rstSAP_SALES1![SLURRYPC]
End If
End If
' Create the Order Type '
If rstSAP_SALES1![CUSTCODE] < "2" Then
rstSAP_SALES1![ORDERTYP] = "09"
Else
rstSAP_SALES1![ORDERTYP] = "01"
End If
' Covert Freight Terms code '
INCO_2X = rstSAP_SALES1![INCO_2]
rstSAP_SALES1![FRTTERMC] = "XXX"
If rstSAP_SALES1![INCOT] = "CIP" Then
If InStrB(INCO_2X, "ADD") <> 0 Then
rstSAP_SALES1![FRTTERMC] = "PPA"
End If
If InStrB(INCO_2X, "PPA") <> 0 Then
rstSAP_SALES1![FRTTERMC] = "PPA"
End If
If InStrB(rstSAP_SALES1![INCO_2], "PPD") <> 0 Then
rstSAP_SALES1![FRTTERMC] = "PPD"
End If
End If
If rstSAP_SALES1![INCOT] = "FCA" Then
rstSAP_SALES1![FRTTERMC] = "COL"
End If
If rstSAP_SALES1![INCOT] = "EXW" Then
rstSAP_SALES1![FRTTERMC] = "WLC"
End If
If rstSAP_SALES1![FRTTERMC] = "XXX" Then
rstSAP_SALES1![FRTTERMC] = rstSAP_SALES1![INCOT]
End If
' Attempt to fix sc = 70 99
FIX_SC = "True"
If rstSAP_SALES1![TRPT] = " " Then
FIX_SC = "False"
End If
If rstSAP_SALES1![TRPT] = "70" Then
FIX_SC = "False"
End If
If rstSAP_SALES1![TRPT] = "99" Then
FIX_SC = "False"
End If
If rstSAP_SALES1![SC] = "70" Then
If FIX_SC = "True" Then
rstSAP_SALES1![SC] = rstSAP_SALES1![TRPT]
End If
End If
If rstSAP_SALES1![SC] = "99" Then
If FIX_SC = "True" Then
rstSAP_SALES1![SC] = rstSAP_SALES1![TRPT]
End If
End If
' Fix MODE
rstSAP_SALES1![Mode] = "UNK"
If rstSAP_SALES1![Mode] = "UNK" Then
If rstSAP_SALES1![PKG_FORM] = "01" Then
If rstSAP_SALES1![SALE_QTY] < 49 Then
rstSAP_SALES1![Mode] = "TSL"
Else
rstSAP_SALES1![Mode] = "RSL"
End If
End If
End If
If rstSAP_SALES1![Mode] = "UNK" Then
If rstSAP_SALES1![PKG_FORM] = "02" Then
If rstSAP_SALES1![SALE_QTY] < 49 Then
rstSAP_SALES1![Mode] = "TBL"
Else
rstSAP_SALES1![Mode] = "RBL"
End If
End If
End If
If rstSAP_SALES1![Mode] = "UNK" Then
If rstSAP_SALES1![PKG_FORM] = "13" Then
If rstSAP_SALES1![SALE_QTY] < 49 Then
rstSAP_SALES1![Mode] = "TRL"
Else
rstSAP_SALES1![Mode] = "RBX"
End If
End If
End If
If rstSAP_SALES1![Mode] = "UNK" Then
If rstSAP_SALES1![PKG_FORM] = "35" Then
If rstSAP_SALES1![SALE_QTY] < 49 Then
rstSAP_SALES1![Mode] = "TRL"
Else
rstSAP_SALES1![Mode] = "RBX"
End If
End If
End If
If rstSAP_SALES1![Mode] = "UNK" Then
If rstSAP_SALES1![PKG_FORM] = "41" Then
If rstSAP_SALES1![SALE_QTY] < 49 Then
rstSAP_SALES1![Mode] = "TRL"
Else
rstSAP_SALES1![Mode] = "RBX"
End If
End If
End If
If rstSAP_SALES1![Mode] = "TSL" Then
rstSAP_SALES1![Mode2] = "TK"
End If
If rstSAP_SALES1![Mode] = "TBL" Then
rstSAP_SALES1![Mode2] = "TK"
End If
If rstSAP_SALES1![Mode] = "TRL" Then
rstSAP_SALES1![Mode2] = "TK"
End If
If rstSAP_SALES1![Mode] = "RSL" Then
rstSAP_SALES1![Mode2] = "RR"
End If
If rstSAP_SALES1![Mode] = "RBL" Then
rstSAP_SALES1![Mode2] = "RR"
End If
If rstSAP_SALES1![Mode] = "RBX" Then
rstSAP_SALES1![Mode2] = "RR"
End If
' Export Processing
If rstSAP_SALES1![Group] = "ZEXP" Then
rstSAP_SALES1![CUSTTYPE] = "EXPORT"
End If
If rstSAP_SALES1![Group] = "ZEXP" Then
rstSAP_SALES1![ORDTYPE] = "01"
End If
' Change Order type for Consignment Orders
'If rstSAP_SALES1![ORTYPNEW] <> " " Then'
'rstSAP_SALES1![ORDTYPE] = rstSAP_SALES1![ORTYPNEW]'
'End If'
.Update
.MoveNext
Count = Count + 1
Loop
End With
rstSAP_SALES1.Close
dbsOmya_2.Close
Set rstSAP_SALES1 = Nothing
Set dbsOmya_2 = Nothing
Exit Function
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Function