Solved

schema.ini - spaces in field name

Posted on 2011-03-24
6
863 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help embedding an image as HTML in my vb.net application 3 50
Direct Mail software 4 44
Alter an update query which rounds 7 33
Query design issue 2 24
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 …
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

895 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

14 Experts available now in Live!

Get 1:1 Help Now