Connect Access Form

How to connect Access form/table with SQL server database?
Ann KAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.