Results 1 to 8 of 8

Thread: [RESOLVED] what to do if table head contains bracket

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Resolved [RESOLVED] what to do if table head contains bracket

    I have a table with one field name "Time (Date + Hour)". Now when I write the code

    Code:
    strSQL = "SELECT [Time (Date + Hour)] FROM tblName"
        rs.CursorLocation = adUseClient
        rs.Open strSQL, con, adOpenDynamic, adLockOptimistic
        MsgBox rs(Time (Date + Hour))
    It shows error code. How can I read the value then?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: what to do if table head contains bracket

    SELECT `Time (Date + Hour)` FROM tblName

    Does this work? Or is the problem with the msgbox?

    You can always rename the name of the field returned to not contain spaces or brackets.

    SELECT [Time (Date + Hour)] AS Time FROM tblName

    something like that...


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Re: what to do if table head contains bracket

    I dont have any problem with SQL. It works fine. But when i want to get values from recordset, Like rs(Time (Date + Hour)), then the problem arises.

    And, I can't change the field name, because of some regulation.

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: what to do if table head contains bracket

    The first line
    strSQL = "SELECT [Time (Date + Hour)] FROM tblName"
    is Ok.
    The problem is in line
    MsgBox rs(Time (Date + Hour))
    It should be:
    MsgBox rs![Time (Date + Hour)]
    or
    MsgBox rs("Time (Date + Hour)")

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Re: what to do if table head contains bracket

    thanx a lot .. So fool of me! .. I should try that before.. Now I'll try

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Re: [RESOLVED] what to do if table head contains bracket

    But it
    Code:
    MsgBox rs![Time (Date + Hour)]
    does not work !!!!!!!!!!!!

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [RESOLVED] what to do if table head contains bracket

    Try to learn the syntax yourself and you will know what you have to do when the field name contains spaces and orther non-alphanumeric character.

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    48

    Re: [RESOLVED] what to do if table head contains bracket

    sorry pal, thought that as I had the opportunity to ask the vb wizards, it may save my time, becoz I am new and really in hurry. Anyway, thanx 4 all ur help. Btw, my problem is solved.

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