Results 1 to 4 of 4

Thread: Creating Database on the fly? How does Access handle string fields?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Quantico, VA, USA
    Posts
    41

    Question

    Two very simple questions: Is it possible to create an Access database on the fly using ADO? If so, how?

    Second: How does access handle string fields? If I create a field of 20 characters, and I have 3 characters of data, does it store spaces or lock up the memory for 20 characters or does it chop the field down to only the amount of space necessary?

    Thanks,
    Chuck
    To err is human, but to apologize frequently is embarassing.

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Item 1, yes. Tom Clunie has posted this in the past, a search of this forum should get you what you want.

    Item 2. There is no varchar in Access, it's going to use the size you specify.

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Regarding item #2, I beg to differ. In Access, when you declare a field as Text, the length you declare is the MAXIMUM number of characters that can be stored in the field - but it is a variable-length field and will only store the number of characters necessary. This is true when you design a table in the Access UI or use a SQL CREATE TABLE statement, such as:

    dbMyDB.Execute "CREATE TABLE MyTable (MyField TEXT(20))"

    Here's an obscure bit of trivia. The ONLY way you can create a FIXED length character field in Access is with SQL and declare a field as CHAR rather than TEXT:

    dbMyDB.Execute "CREATE TABLE MyTable (MyField CHAR(20))"

    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Quantico, VA, USA
    Posts
    41

    Cool

    Thanx for your help JHausmann and BruceG. I'm posting this for anyone following this line. This is Clunietp's code for creating a DB in ADO. Thanx to Clunietp for posting it in the first place.

    -Chuck
    ********************************************************
    Clunietp
    Guru
    Registered: Oct 1999
    Posts: 1877

    Create a database using ADO:

    code:

    'uses ADO 2.x for DDL and security
    Dim strConnectionStringOfNewDB As String
    Dim objCat As ADOX.Catalog

    'instantiate catalog object
    Set objCat = New ADOX.Catalog

    'connection string of new db -- includes driver/db type and location
    strConnectionStringOfNewDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\NewDB.mdb"

    'create it
    objCat.Create strConnectionStringOfNewDB

    'cleanup
    Set objCat = Nothing
    To err is human, but to apologize frequently is embarassing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width