Solved

schema.ini - spaces in field name

Posted on 2011-03-24
6
854 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now