Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

ODBC connection

Question posted by: ddtpmyra (Member) on June 27th, 2008 11:25 PM
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 Inverness's Avatar
Stewart Ross Inverness
Forum Leader
1,131 Posts
June 28th, 2008
06:35 AM
#2

Re: ODBC connection
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

Reply
ddtpmyra's Avatar
ddtpmyra
Member
64 Posts
June 30th, 2008
06:02 PM
#3

Re: ODBC connection
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?

Reply
Stewart Ross Inverness's Avatar
Stewart Ross Inverness
Forum Leader
1,131 Posts
June 30th, 2008
07:47 PM
#4

Re: ODBC connection
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. strSQL = "SELECT [field1], [field2], ... , [fieldn] "
  3. strSQL = strSQL & " FROM [linked table] INNER JOIN [another table] "
  4. strSQL = strSQL & " ON [linked table].[some field] = [another table].[some field];"
  5. 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

Expand|Select|Wrap|Line Numbers
  1. IF somecondition THEN
  2.   Me.Recordsource = "[Query1]"
  3. else
  4.   Me.Recordsource = "[Query2]"
  5. end if


-Stewart

Reply
ddtpmyra's Avatar
ddtpmyra
Member
64 Posts
July 3rd, 2008
05:47 PM
#5

Re: ODBC connection
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!

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,086 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Microsoft Access / VBA Forum Contributors