Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

schema.ini - spaces in field name

Posted on 2011-03-24
6
Medium Priority
?
1,019 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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 2000 total points
ID: 35213979
Glad it worked for you!  Will you please mark the "Accepted Solution" and award points?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

636 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