CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2003
    Posts
    6

    Setting the format property using create table query

    Hello Friends
    I am creating a table using create table query(using the back end - Ms access). My table contains boolean fields.
    i am executing following code.

    option explicit
    dim y as boolean
    dim n as boolean

    Form_load
    y=True
    n=False

    'creating a table using connection con
    con.execute "create table try(a yesno, b yesno)"

    but when i am adding data to the table if value is true it stores -1
    and if false it stores 0.
    want to store true and false instead.
    but now for that i have to set format property of the fields in Access. Do not want to do this explicitly. want it to be set while creating the table.
    Can anybody help me for this? want to know the syntax to set the format property of the field.
    it's urgent.
    thanks in advance!

  2. #2
    Join Date
    Aug 2003
    Location
    Buenos Aires, Argentina
    Posts
    513
    Try to save the records with the string True and False but not within '':

    db.Execute "Insert Into Table (Field1, Field2) Values (True, False)"

  3. #3
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Boolean values are represented by 0 or 1 in MS Access - there is no actual 'true' or 'false', however they do have 'yes' or 'no' (which is pretty much the same thing).

    If you write to a boolean field, you must leave out the quotes & vb will convert the word true to 1

    This is really only a concern when you actually look at the table though.
    Be nice to Harley riders...

  4. #4
    Join Date
    Nov 2003
    Posts
    6
    Originally posted by vbUserName
    Try to save the records with the string True and False but not within '':

    db.Execute "Insert Into Table (Field1, Field2) Values (True, False)"
    Hello
    thanks for sending the reply
    I tried above code
    .But still it inserts -1 & 0 only.
    I want to set the format using front end.
    kindly help me for this
    thanks

  5. #5
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    Better and easy way is (Not methodical Though) to have a template of that table in the database and copy it to what u want

  6. #6
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    You obviously either didn't read my reply, or didn't understand my reply.

    True and False are represented as one or zero in ms access. Full stop, end of story.

    If you want to see the word 'True' or 'False', then make it a string.
    Be nice to Harley riders...

  7. #7
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    Twodogs idea is correct

    better to use a string
    so that u can do what ever u like.It is your control

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

Featured