?
Solved

MS access to SQL Server

Posted on 2014-03-31
3
Medium Priority
?
555 Views
Last Modified: 2014-04-02
I need to connect my Access 2010 form with SQL Server 2012 table ”tblMaster”  seating in SQL Server database named “Production_db” .
I would like to use ADO to connect and pull out some records from table” tblMaster”.
For that reason I probably need to initiate reference Microsoft Active X Data Object control  2.8 in MS Access reference settings
I would like to have command button on form which I click and make connection to table in SQL Server database  then select  particular record  from table and then display it on form fields.
 My PC is on company network.
SQL Server database is seating on one company server named Prod_Serv  that is on company network too.
I need code that will be behind this command button.
0
Comment
Question by:Taras
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 39

Expert Comment

by:PatHartman
ID: 39967886
Is there some particular reason that you don't want to use a linked table and a bound form?
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 39968921
If you can't use linked tables, then you must do this:

1. Create an ADO or DAO connection. Since you're dealing with server-based data, ADO would be the better choice, and as you indicate you would need to set a reference to the ADO library:

Dim con As New ADODB.Connection
con.ConnectionString = "Your Connection String"
con.Open

Here's a good resource for connection strings: http://www.connectionstrings.com/sql-server/

2. Create a recordset using that connection:

Dim rst As New ADODB.Recordset
rst.Open "SELECT * FROM SomeTable WHERE IDField=123", con

You should then have the data from "SomeTable" in that recordset, for the defined criteria. You could then use one of several methods to show that data. If it's just a few fields, you could do this:

Me.Textbox1 = rs("Field1")
Me.Textbox2 = rs("Field2")
and so on

If there are a LOT, then you can (a) create textboxs with EXACTLY the same name as the recordset fields and then (b) loop through the Fields collection of the recordset and set the value:

Dim i as Integer
For i = 0 to rs.Fields.Count - 1
  Me.Controls(rs.Fields(i).Name) = rs.fields(i)
Next i
0
 

Author Closing Comment

by:Taras
ID: 39972132
Thanks a lot
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question