Solved

schema.ini - spaces in field name

Posted on 2011-03-24
6
962 Views
Last Modified: 2012-05-11
Hello,

I am creating  schema.in'si based on  table's.  I just realized that they have spaces in some of the field names.  How can I fix the following code (courtesy of Microsoft) to accomidate spaces.  I know I need to have quotes around the columnName but nothing I have tried work.

Any help would be greatly appreciated!!!!

T
Option Compare Database
Option Explicit
 Public Function CreateSchemaFile(bIncFldNames As Boolean, _
                                       sPath As String, _
                                       sSectionName As String, _
                                       sTblQryName As String) As Boolean
         Dim Msg As String ' For error handling.
         On Local Error GoTo CreateSchemaFile_Err
         Dim ws As Workspace, db As Database

         Dim tblDef As TableDef, fldDef As Field
         Dim i As Integer, Handle As Integer
         Dim fldName As String, fldDataInfo As String, fldCaption As String
         ' -----------------------------------------------
         ' Set DAO objects.
         ' -----------------------------------------------
         Set db = DBEngine.Workspaces(0).OpenDatabase(Forms!frm_Import!txt_DBApp)
        sPath = Forms!frm_Import!txt_txtPath

         ' -----------------------------------------------
         ' Open schema file for append.
         ' -----------------------------------------------
         Handle = FreeFile
         Open sPath & "schema.ini" For Output Access Write As #Handle
         ' -----------------------------------------------
         ' Write schema header.
         ' -----------------------------------------------
         Print #Handle, "[" & sSectionName & "]"
         Print #Handle, "ColNameHeader = " & _
                         IIf(bIncFldNames, "True", "False")
         Print #Handle, "CharacterSet = ANSI"
         Print #Handle, "Format = TabDelimited"
         
       
         ' -----------------------------------------------
         ' Get data concerning schema file.
         ' -----------------------------------------------
         Set tblDef = db.TableDefs(sTblQryName)
         With tblDef
            For i = 0 To .Fields.Count - 1
               Set fldDef = .Fields(i)
               With fldDef
                    fldName = .Name
                  Select Case .Type
                     Case dbBoolean
                        fldDataInfo = "Bit"
                     Case dbByte
                        fldDataInfo = "Byte"
                     Case dbInteger
                        fldDataInfo = "Short"
                     Case dbLong
                        fldDataInfo = "Integer"
                     Case dbCurrency
                        fldDataInfo = "Currency"
                     Case dbSingle
                        fldDataInfo = "Single"
                     Case dbDouble
                        fldDataInfo = "Double"
                     Case dbDate
                        fldDataInfo = "Date"
                     Case dbText
                        fldDataInfo = "Char"
                     Case dbLongBinary
                        fldDataInfo = "OLE"
                     Case dbMemo
                        fldDataInfo = "LongChar"
                     'Case dbGUID
                        'fldDataInfo = "Char 16"
                  End Select
                  Print #Handle, "Col" & Format$(i + 1) _
                                  & "=" & fldName & Space$(1) _
                                 & fldDataInfo
               End With
            Next i
         End With
         'MsgBox sPath & "SCHEMA.INI has been created."
         CreateSchemaFile = True
CreateSchemaFile_End:
         Close Handle
         Exit Function
CreateSchemaFile_Err:
         Msg = "Error #: " & Format$(Err.Number) & vbCrLf
         Msg = Msg & Err.Description
         MsgBox Msg
         Resume CreateSchemaFile_End
      End Function

''Test
'?CreateSchemaFile(True,"P:\Data_Migration\Databases\Audit DB\AuditDB\Testing\","arofin_aso.txt","Employees")








0
Comment
Question by:Halia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:GeoffHarper
ID: 35210300
How about another delimiter (like a comma) instead of the Space$(1) ?
0
 

Author Comment

by:Halia
ID: 35210388
Thank you but that did not work.  I need fldName to be created so that if the Field name is Last Name it comes out "Last Name" in the schema.ini.
0
 
LVL 4

Expert Comment

by:GeoffHarper
ID: 35210411
Ok,


Print #Handle, "Col" & Format$(i + 1) _
             & "=""" & fldName & """"_
             & Space$(1) _
             & fldDataInfo

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Halia
ID: 35210804
Ok...I will try that and let you know.  I did try that, sort of, but I added extra"&".

Thank you!!!!!
0
 

Author Comment

by:Halia
ID: 35211233
That WORKED!!!!!!!   Thank you so much!
0
 
LVL 4

Accepted Solution

by:
GeoffHarper earned 500 total points
ID: 35213979
Glad it worked for you!  Will you please mark the "Accepted Solution" and award points?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question