Results 1 to 2 of 2
  1. #1
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199

    Error 2391

    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!!!
    Last edited by RuralGuy; 07-03-2013 at 11:01 AM. Reason: Added code tags and indenting

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Have you step debugged? Follow code as it executes, see where it is deviating from expected behavior, fix, debug again. Refer to link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Replies: 1
    Last Post: 05-11-2012, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums