Connect Access Form

How to connect Access form/table with SQL server database?
Ann KAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can create linked tables to the SQL database, and "bind" your forms to them by setting the Recordsource of the form to your Table.

You can also create queries on those tables, and bind your form to those.

To create links, click the External data tab >> New Data Source >> From Database >> From SQL, and follow the prompts. Note that's for Access 2016; other versions may do this slightly different, but there are plenty of resources that show how.

Also note that if you're going to be working with SQL Server, you should adhere to proper client-server principles. For example, with SQL you generally do NOT base a form on an entire table, but instead you prompt the user for the data they need and pull only that. If the user wants to work with Customer "Ford Motor Company", you'd create an SQL string (or modify a stored query) to ONLY pull the Ford data.

You also have to be careful to not use any Access-specific functionality in your Forms/REports/Queries. For example writing this query:

SELECT * FROM Customer WHERE Customer=Forms!CustomerForm!txCutomer

could force Access to retrieve all records from that table, and do the filtering client-side.
0
 
Ann KAuthor Commented:
Its not showing From Database
screenshot.png
0
 
Gustav BrockCIOCommented:
It is "ODBC Database". That will create a connection to the database. Of course, you must know its address (hostname) and have a valid username and password.
When connected, you can link the table(s) you need.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Ann KAuthor Commented:
Is it possible to bypass ODBC and type a connection string inside the form?
0
 
Gustav BrockCIOCommented:
You could use ADO to connect and use an unbound form:

Optimizing Microsoft Office Access Applications Linked to SQL Server

but ODBC is the simple and fastest method, and you can use a bound form. Either create a DSN for the connection, or use code to create a DSN-less connection (browse for this).
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
0
 
PatHartmanCommented:
SELECT * FROM Customer WHERE Customer=Forms!CustomerForm!txCutomer
In this case, Access will convert the form reference to a literal and send the literal to the server.  However, functions can get in the way.

Select MyFunc(somefield) as Result, From mytable where someID = 99  -- Access recognizes that MyFunc() is a UDF and therefore unknown to the server.  It will send the following query to the server:

Select somefield from mytable where someID = 99  --- and then when the recordset (which will contain ONLY records where smeID = 99) is returned, run its' own query to run the function on  every row.

However,

Select somefield from mytable Where MyFunc(somefield) = 45  --  Access will again recognize that the query cannot be sent as is to the server but in this case, Access will request ALL the rows since it has no way to know what the function is doing.  The query sent to the server will bel:

Select somefield from mytable  --- with NO criteria so ALL rows are returned.  This is what you need to avoid.

Is it possible to bypass ODBC and type a connection string inside the form?
It would be ever so much more helpful if you would tell us what you want to do rather than how you think you need to do it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.