ODBC connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    ODBC connection

    I very new on Access scripting and I wanted to add on my event like load report and odbc connection so I can execute sql query besides the query attach on the said report.

    thanks
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi, and welcome to Bytes. Could you give some more detail of what it is you are asking us to help you with? Is it the use of custom events, for example? We need a question to be clearly stated so that we can avoid guesswork which would not help you or those who are trying to answer your question!

    There are Posting Guidelines on how to ask a question in this forum which I would ask you to read - linked here for ease of access.

    -Stewart

    Comment

    • ddtpmyra
      Contributor
      • Jun 2008
      • 333

      #3
      I establish the link of tables inside the access already using the access wizard, I want to do the select query inside on load event (report or form) where it will supply all the information on its equivalent field.

      how to do hardcoding?

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        There is still very little information in your post. However, to answer what I think you are asking, you can set the recordsource of the current form to SQL built as a string value within the On Load event of the form like this - bearing in mind that I do not know the names of your linked tables or their fields, nor how many tables you want to use in your code, so I cannot use real field and table names in the example below:
        Code:
        Dim strSQL as String
        strSQL = "SELECT [field1], [field2], ... , [fieldn] "
        strSQL = strSQL & " FROM [linked table] INNER JOIN [another table] "
        strSQL = strSQL & " ON [linked table].[some field] = [another table].[some field];"
        Me.Recordsource = strSQL
        The Me operator is a shorthand way of referring to the current form in this case.

        I would advise building Access queries using the query editor and using these as the record source for your form instead. You can also assign the relevant query dynamically as the recordsource for your form in the On Load event if you wish, like this

        Code:
        IF somecondition THEN
          Me.Recordsource = "[Query1]"
        else
          Me.Recordsource = "[Query2]"
        end if
        -Stewart

        Comment

        • ddtpmyra
          Contributor
          • Jun 2008
          • 333

          #5
          Hi Stewart,

          thanks for looking into this, but i cannot use the 'me.recordset' because I have query set on the report properties already.

          During the event 'on load' i want to run a additional hard coded 'select query' and assigned it on a txt field.

          Please help for the script.

          thanks!

          Comment

          Working...