ACC: How to Import a Microsoft Windows Cardfile Data File

Last reviewed: August 29, 1997
Article ID: Q98797
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes a sample user-defined function that you can use to import a Microsoft Windows Cardfile (.crd) file.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

MORE INFORMATION

The function below can be used to import a Microsoft Windows Cardfile data file. To use this function, you need to add it to a new or existing Microsoft Access module. The function is designed to work with Cardfiles created with Microsoft Windows versions 3.0, 3.1, and 3.11 only. In addition, you need to create the following table in your database before you run the function:

   Table Name: CardFile
   --------------------
   Field: Title
      Type: Text
      Length: 50
   Field: Comment
      Type: Text
      Length: 255

You can run the function from the Debug window (Immediate window in versions 1.x and 2.0) or you can call it from a command button by setting a command button's OnClick property as follows:

   =Import_CRD()

NOTE: In Microsoft Access version 1.x, the OnClick property is called the OnPush property.

Make sure to substitute the correct path and filename for the .crd file you want to import in the function below. Or you can pass the path and filename to the function as a string argument.

   Code for the Import_CRD() Function
   ----------------------------------

      Option Compare Binary
      Option Explicit

      Type CRD_Record_Type
         Reserved As String * 6
         Position As Long
         Flag As String * 1
         Index As String * 40
         EndOfRecord As String * 1
      End Type

      Function Import_CRD ()
         Const VER30 = &H474D&
         Const VER31 = &H5252&
         Const VER30_NUMRECORDS_OFFSET = &H4&
         Const VER31_NUMRECORDS_OFFSET = &H8&
         Const VER30_FIRSTENTRY = &H6&
         Const VER31_FIRSTENTRY = &HA&

         Dim MyDB As Database
         Dim MyTable As Table

         Dim FileNum#
         Dim NumberOfCards%, NextRecord&, I%, VersionInfo%, EntryLength%
         Dim CRD_Record As CRD_Record_Type
         Dim Message$
         Dim n As Integer

         Set MyDB = CurrentDB()
         Set MyTable = MyDB.OpenTable("CardFile") 'For MS Access 1.x, 2.0
         ' Set MyTable = MyDB.OpenRecordset("CardFile") 'For MS Access 7.0

         FileNum# = FreeFile
         ' Be sure to supply the correct path and filename for the .CRD
         ' file.
         Open "c:\my_cards.crd" For Binary As FileNum#

         'The number of files in the .CRD file is at the 4 bytes offset.
         Get #FileNum, , VersionInfo%
         If VersionInfo% = VER31 Then
            Get #FileNum, VER31_NUMRECORDS_OFFSET, NumberOfCards%
            NextRecord& = VER31_FIRSTENTRY
         ElseIf VersionInfo% = VER30 Then
            Get #FileNum, VER30_NUMRECORDS_OFFSET, NumberOfCards%
            NextRecord& = VER30_FIRSTENTRY
         End If

         For I% = 1 To NumberOfCards%

            Get #FileNum, NextRecord&, CRD_Record
            Get #FileNum, CRD_Record.Position + 3, EntryLength%

            Message$ = Space$(EntryLength%)

            Get #FileNum, CRD_Record.Position + 5, Message$

             MyTable.AddNew
                n = InStr(CRD_Record.Index, Chr$(0))
                If n > 1 Then
                   MyTable.Title = Left$(CRD_Record.Index, n - 1)
                ElseIf n = 1 Then
                   MyTable.Title = ""
                Else
                   MyTable.Title = CRD_Record.Index
                End If

                n = InStr(Message$, Chr$(0))
                If n > 1 Then
                   MyTable.Comment = Left$(Message$, n - 1)
                ElseIf n = 1 Then
                   MyTable.Comment = ""
                Else
                   MyTable.Comment = Message$
                End If
             MyTable.Update

             NextRecord& = NextRecord& + Len(CRD_Record)

         Next I%
         Close
      End Function

NOTE: To avoid compile errors when using this code in Microsoft Access 7.0 and 97:

In Microsoft Access 97, open a module in Design view and click References on the Tools menu. Click Microsoft DAO 2.5/3.5 Compatibility Library. If Microsoft DAO 3.5 Object Library is already selected, clear it first.

In Microsoft Access 7.0, open a module in Design view and click References on the Tools menu. Click Microsoft DAO 2.5/3.0 Compatibility Library. If Microsoft DAO 3.0 Object Library is already selected, clear it first.

REFERENCE

For more information about this topic, please see the following article here in the Microsoft Knowledge Base:

   ARTICLE-ID:  Q75492
   TITLE:       Converting Windows Cardfile Files to Text Format


Additional query words: .crd
Keywords : IntpOthr kbinterop PgmHowTo PgmFilM
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.