Wednesday, October 12, 2005

Adding Column Field on Table imported from Xls

I used to get data from Finance in Excel format and they wanted me to put them into an Access Database. The imported tables always end up missing with few column fields necessary in the MS Access Reporting later on. Here is how I did it.

Private Sub CMD_ImportXlsTable_Click()

On Error GoTo Err_CMD_ImportXlsTable_Click

If IsNull(Me.FileNameCombo) Then

prompt = MsgBox("Please choose the Filename to process.", vbOKOnly, "Warning!!!")

Exit Sub

Else

ImportXlsTable

If Me.FileNameCombo = 2 Then 'WIRELESS BALANCE ON HAND

DoCmd.SetWarnings False

'***This corrects the entry WNPM into WNPM-W StockRoom

DoCmd.OpenQuery "Update Wireless WNPM to WNPM-W Q", acViewNormal

'***This corrects the entry in LOC_AV field by removing the blank prefixes

DoCmd.OpenQuery "Update Imp BOH LOC_AV Q", acViewNormal

DoCmd.SetWarnings True

Else

GoTo ProcessCartons

End If

ProcessCartons:

If Me.FileNameCombo = 7 Then 'Cartons Wireless issued not shipped

'***ADD Additional Column Fields called:

'***Found, Remarks

Dim SQL As String

For i = 1 To 4

Select Case i

Case 1

SQL = "ALTER TABLE [Wcartons issued not shipped] ADD COLUMN Found YESNO"

DoCmd.RunSQL SQL

Case 2

SQL = "ALTER TABLE [Wcartons issued not shipped] ADD COLUMN Remarks Text(100)"

DoCmd.RunSQL SQL

Case 3

SQL = "ALTER TABLE [Wcartons issued not shipped] ADD COLUMN Count Long"

DoCmd.RunSQL SQL

Case 4

SQL = "ALTER TABLE [Wcartons issued not shipped] ADD COLUMN IBIN Text(50)"

DoCmd.RunSQL SQL

End Select

Next i

Else

'Exit Sub

End If

End If

Exit_CMD_ImportXlsTable_Click:

Exit Sub

Err_CMD_ImportXlsTable_Click:

MsgBox Err.Description

Resume Exit_CMD_ImportXlsTable_Click

End Sub





No comments: