hi I have written this code:
Code:
On Error GoTo Err_cmd_vimport_Click
Dim f As Object
Dim srs5 As DAO.Recordset
Dim fname As String
Dim str2, usrname As String
Dim str_qry As String
Dim Vname As Field
Dim Vch_count As Integer
Dim dupvchrs As Variant
DoCmd.SetWarnings False
DoCmd.RunSQL ("Delete * from Temp")
DoCmd.SetWarnings True
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.Show
If f.SelectedItems.Count > 0 Then
fname = f.SelectedItems(1)
'Check on length of vouchers nos length - START
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Temp", fname, True
'DoCmd.SetWarnings False
'DoCmd.RunSQL "Delete * from Temp where Card_no is null"
'DoCmd.RunSQL "INSERT INTO Invalid_Vouchers (VoucherNo)SELECT VoucherNo FROM Temp WHERE LEN(VoucherNo)<>18;"
'DoCmd.SetWarnings True
'Mlook = DCount("*", "Invalid_Vouchers")
'If Mlook <> 0 Then
' MsgBox "Invalid vouchers Found Check File 'C:\Invalid_vouchers for Details"
' DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Invalid_Vouchers", "C:\Invalid_Vouchers.xls", True
' DoCmd.SetWarnings False
'DoCmd.RunSQL "Delete * from Invalid_Vouchers"
' DoCmd.SetWarnings True
' Exit Sub
'End If
'Check on length of vouchers nos length - END
'Check on duplicate Voucher numbers - START
'str_qry = ""
'str_qry = "INSERT INTO Duplicate_Card(Ref_No,Total_duplicates)"
'str_qry = str_qry & " SELECT Ref_no, Count(VoucherNo)"
'str_qry = str_qry & " FROM Temp GROUP BY Ref_no HAVING Count(Ref_no)>1;"
'DoCmd.SetWarnings False
'DoCmd.RunSQL (str_qry)
'DoCmd.SetWarnings True
'str_qry = ""
'str_qry = "INSERT INTO Duplicate_Card(Ref_No,Total_duplicates)"
'str_qry = str_qry & " SELECT Cards.Ref_No ,'1' FROM Cards"
'str_qry = str_qry & " inner join Temp on Cards.Ref_No=Temp.Ref_No;"
'DoCmd.SetWarnings False
'DoCmd.RunSQL (str_qry)
'DoCmd.RunSQL "Delete * from Duplicate_Card where Ref_No is null"
'DoCmd.SetWarnings True
'Mcount = DCount("*", "Duplicate_Card")
'If Mcount <> 0 Then
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Duplicate_Card", "C:\Duplicates.xls", True
'MsgBox "Unable to Import as Duplicate Reference number in File Found ..check file C:\Duplicates.xls for Details"
'DoCmd.SetWarnings False
'DoCmd.RunSQL "Delete * from Duplicate_Card"
'DoCmd.SetWarnings True
'Check on duplicate Voucher numbers - END
'Else
'stamping Vouchers table
DoCmd.SetWarnings False
DoCmd.RunSQL ("insert into Cards(Card_No,Ref_No,Uploaded_Date) select Card_No,Ref_No,now() from Temp")
Vch_count = DCount("*", "Temp")
DoCmd.SetWarnings True
'Call Stock_Update
DoCmd.SetWarnings False
DoCmd.RunSQL "Update Cards set Uploaded_Date=now()where Uploaded_Date is null"
DoCmd.SetWarnings True
MsgBox Vch_count & " Vouchers Imported Successfully"
Else
MsgBox " U didnt select a File"
End If
'error handling
Exit_cmd_vimport_Click:
Exit Sub
Err_cmd_vimport_Click:
If Err.Number = 2391 Then
MsgBox "Incorrect File Selected!!"
Resume Exit_cmd_vimport_Click
Else
MsgBox Err.Description
Resume Exit_cmd_vimport_Click
End If
its givind error 2391 incorrect file selected Please help!!!