Access FE to SQL Server BE
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Access FE to SQL Server BE
What do i need to look out for if i use an existing Access FE that was linked to an Access BE but now is to be linked to a SQL Server BE.
Are there any VBA code considerations involved?
What needs to be changed in the Access FE?
Are there any VBA code considerations involved?
What needs to be changed in the Access FE?
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
Make sure that all tables in the SQL Server database have a unique index.
The SQL dialect used in SQL Server uses _ and % as wildcards instead of ? and *, so you may have to update your queries and SQL statements.
The SQL dialect used in SQL Server uses _ and % as wildcards instead of ? and *, so you may have to update your queries and SQL statements.
Best wishes,
Hans
Hans
-
- Lounger
- Posts: 47
- Joined: 09 Feb 2010, 11:30
- Location: OH USA
Re: Access FE to SQL Server BE
What I have found to be a bugaboo is that in my organization we have to have SQLServer dba's to monitor the backend. What this means to me is that everytime a structure change needs to be made in the tables, I have to solicit the services of the dba; not always the best use of time.
Also, be sure to set up an ODBC connection so that your front end knows where the back end is.
Also, be sure to set up an ODBC connection so that your front end knows where the back end is.
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
Hans,
The wildcards only need to be like that if i use passthru queries or if in an ADP access FE, isn't that right?
aard,
I already have the DSNs setup as it has to select one of about 8 different SQL Server databases.
The wildcards only need to be like that if i use passthru queries or if in an ADP access FE, isn't that right?
aard,
I already have the DSNs setup as it has to select one of about 8 different SQL Server databases.
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
You should use passthrough queries whenever possible - they are much more efficient than local queries.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
I have noted the pass thru queries.
Is there any doco on this i can read?
Is there any doco on this i can read?
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 4StarLounger
- Posts: 482
- Joined: 24 Jan 2010, 15:02
- Location: Colorado, USA
Re: Access FE to SQL Server BE
With regard to passthrough queries, we do use them, but only when the performance of an Access query isn't acceptable. For most simple Access queries (two or less joins), the ODBC driver will convert the Access SQL string to SQL Server dialect and actually run the query in SQL Server. On average we find about 90 percent of the queries run just fine. Another trick we use is to create views in SQL Server (like a query in Access), and then link to the view so that Access sees it as a table. In some cases you may need to create an Indexed View if the dataset is large, but in most cases that isn't necessary.
Wendell
You can't see the view if you don't climb the mountain!
You can't see the view if you don't climb the mountain!
-
- 3StarLounger
- Posts: 331
- Joined: 11 Feb 2010, 03:55
- Location: Land O Lakes, FL
Re: Access FE to SQL Server BE
There is one potentially major difference when using MDB vs SQL backend. Access fills an autonumber field as soon as you make a record dirty. SQL only does it when it writes new record.Pat wrote:What do i need to look out for if i use an existing Access FE that was linked to an Access BE but now is to be linked to a SQL Server BE.
Are there any VBA code considerations involved?
What needs to be changed in the Access FE?
Mark Liquorman
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
How do you get the autonumber field from SQL Server after it is written, i have noticed in the code it uses this. Is there a certain technique to get that number?Mark L wrote:There is one potentially major difference when using MDB vs SQL backend. Access fills an autonumber field as soon as you make a record dirty. SQL only does it when it writes new record.Pat wrote:What do i need to look out for if i use an existing Access FE that was linked to an Access BE but now is to be linked to a SQL Server BE.
Are there any VBA code considerations involved?
What needs to be changed in the Access FE?
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
Let's say that the AutoNumber field is named ID and that you have opened a DAO recordset named rst on the table.
With a local Access table, you can use code like this:
Dim lngID As Long
' Create a new record
rst.AddNew
' Get the value of the AutoNumber field of the new record
lngID = rst!ID
rst!OtherField = "Something"
' Save the record
rst.Update
For a linked SQL Server table, lngID would not be assigned the value of the AutoNumber field in the new record, but the value of the record that was active before AddNew, because SQL Server will only determine this value when the record is saved.
Dim lngID As Long
' Create a new record
rst.AddNew
rst!OtherField = "Something"
' Save the new record
rst.Update
' Move to the record just created
rst.Bookmark = rst.LastModified
' Retrieve the value of the AutoNumber field
lngID = rst!ID
With a local Access table, you can use code like this:
Dim lngID As Long
' Create a new record
rst.AddNew
' Get the value of the AutoNumber field of the new record
lngID = rst!ID
rst!OtherField = "Something"
' Save the record
rst.Update
For a linked SQL Server table, lngID would not be assigned the value of the AutoNumber field in the new record, but the value of the record that was active before AddNew, because SQL Server will only determine this value when the record is saved.
Dim lngID As Long
' Create a new record
rst.AddNew
rst!OtherField = "Something"
' Save the new record
rst.Update
' Move to the record just created
rst.Bookmark = rst.LastModified
' Retrieve the value of the AutoNumber field
lngID = rst!ID
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
That is exactly what i am looking for, thank you.
In one of the tables there is a field that is a copy of the autonumber field (not my design, i have inherited this database) in a field called BookingNo, does the rst.Bookmark = rst.LastModified command enable the edit of that last record or do i have to use rst.Edit after that bookmark command?
In one of the tables there is a field that is a copy of the autonumber field (not my design, i have inherited this database) in a field called BookingNo, does the rst.Bookmark = rst.LastModified command enable the edit of that last record or do i have to use rst.Edit after that bookmark command?
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
In DAO, you have to use
rst.Edit
before you start editing the record; rst.Update takes the record out of edit mode.
rst.Edit
before you start editing the record; rst.Update takes the record out of edit mode.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
Thanks Hans, i thought as much.
so is the following correct?
Dim lngID As Long
' Create a new record
rst.AddNew
rst!OtherField = "Something"
' Save the new record
rst.Update
' Move to the record just created
rst.Bookmark = rst.LastModified
' put the record into Edit mode
rst.Edit
' Update the BookingNo field with the AutoNumber field
rst!BookingNo = rst!ID
' Retrieve the value of the AutoNumber field
lngID = rst!ID
' Save the record back to the database
rst.Update
so is the following correct?
Dim lngID As Long
' Create a new record
rst.AddNew
rst!OtherField = "Something"
' Save the new record
rst.Update
' Move to the record just created
rst.Bookmark = rst.LastModified
' put the record into Edit mode
rst.Edit
' Update the BookingNo field with the AutoNumber field
rst!BookingNo = rst!ID
' Retrieve the value of the AutoNumber field
lngID = rst!ID
' Save the record back to the database
rst.Update
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
That looks OK; if you don't need the value of the ID for other purposes, you can omit the line
lngID = rst!ID
(and the declaration of lngID); you already assign the value of the ID field directly to BookingNo.
lngID = rst!ID
(and the declaration of lngID); you already assign the value of the ID field directly to BookingNo.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
Thanks Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
Will the Sql Server code above work for Access as well? I would presume so, am i correct?HansV wrote:Let's say that the AutoNumber field is named ID and that you have opened a DAO recordset named rst on the table.
With a local Access table, you can use code like this:
Dim lngID As Long
' Create a new record
rst.AddNew
' Get the value of the AutoNumber field of the new record
lngID = rst!ID
rst!OtherField = "Something"
' Save the record
rst.Update
For a linked SQL Server table, lngID would not be assigned the value of the AutoNumber field in the new record, but the value of the record that was active before AddNew, because SQL Server will only determine this value when the record is saved.
Dim lngID As Long
' Create a new record
rst.AddNew
rst!OtherField = "Something"
' Save the new record
rst.Update
' Move to the record just created
rst.Bookmark = rst.LastModified
' Retrieve the value of the AutoNumber field
lngID = rst!ID
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
The code should work OK in Access, but as mentioned earlier in this thread, it could be done in a slightly easier way if the data are stored in an Access database since the new AutoNumber value is available as soon as you modify any field in the new record, you don't have to save it first.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Access FE to SQL Server BE
The reason i ask this is that i converted all their databases for this app to SQL Server and accrdingly changed the code to suit SQL Server. Now i find out that they require one of the databases left in Access, hence the question.
Since they may change their mind in the future i thought if the code works inAccess as well then i dont need to keep changing this code.
Thanks Hans, Welcome back, hope you had a good break.
Since they may change their mind in the future i thought if the code works inAccess as well then i dont need to keep changing this code.
Thanks Hans, Welcome back, hope you had a good break.
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access FE to SQL Server BE
If you want to be able to use the same code for Access and SQL backends, it is indeed best to use the code that works in SQL Server.
And thanks, I had a wonderful holiday in Italy.
And thanks, I had a wonderful holiday in Italy.
Best wishes,
Hans
Hans