2

6 Reasons why you should always use Access with SQL Server

Posted by Juan Soto on January 25, 2012 in Access Help, SQL Server

If you’re having a hard time convincing management to use Access with SQL Server, then use this post as ammunition to get your point across:

Reason #1: Security
I’ve walked into situations where new clients are storing their customer’s credit card info, (including the three digits on the back), along with their billing address, home address and other confidential information in an Access backend. My reaction was to immediately notify them via a certified letter and as their consultant, I recommended that they cease and desist from using Access to store such highly personal information, and instead migrate to SQL Server. Otherwise I’m outta there. The fact is people can and will walk out with your Access backend on a thumb drive. This cannot happen with a SQL Server. Plus SQL Server integrates with Active Directory, has native encryption, and other security enhancements, Access doesn’t have this.

LIVE From Chicago Thursday January 26th, join us for Access KungFu, click here for more details.

Reason #2: Reliability

When you have users using Access backend, they’re all sharing a single data file and essentially cooperating and trusting one other to share nicely. If there’s a network issue or problem with one workstation, it could compromise the data file. This simply does not happen with SQL Server, it’s not affected by PC or Access crashes and is a more reliable environment for your data.

Reason #3: Processing Speed

When it comes to raw computational power you just can’t compare Access with SQL Server. If done right, your Access application should sizzle, pop and process large query operations with ease. SQL Server stored procedures and views are just no match for Jet.

Reason #4: Backups

Have you ever tried backing up an open Access file? Or have you come in the next day only to find your file corrupted and unusable? You can perform backups of your SQL databases while users are in the app.

Reason #5 Free

SQL Server Express 2008R2 will let you store up to 10 gigabytes of data and it is free to use. Of course it is not entirely free if you have to purchase a server, (it can be installed on a powerful workstation too), or you have to hire a professional Access developer to convert to SQL Server, but at least you don’t have to pay for this awesomeness. Don’t walk, run and get your copy today.

Reason #6: Web Enabled Access Databases (Data in the cloud)

SQL Server is the only way you can use full blown Access apps over a WAN, VPN or the Internet. Sure, you can also use Access Web Services, if you only need a simple app. But if you need to use all of what Access has to offer you can’t beat storing the data in the cloud and using Access anywhere in the world.

SQL Server and Access, Unbeatable

Next time someone says you don’t need SQL Server for your Access application I hope these six points and the posts linked in the article will help you convince them otherwise.

LIVE From Chicago Thursday January 26th, join us for Access KungFu, click here for more details.

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

 
11

Web training session January 26th live from Chicago!

Posted by Juan Soto on January 21, 2012 in Access Help

I’ll be presenting at this month’s Chicago Access User’s Group. (www.CAUG.com) It will be broadcast-ed live via the web as I present my newest topic:

Access Kung Fu – Tap into your inner VBA Sensei

We will discuss three topics, TempVars, Enums and Classes.

  • TempVars are a great way to store global variables in your application, use them everywhere: your code, queries, forms, and reports. We will discuss why they are a better alternative than a global module variable.
  • Enums are a convenient way to detail related constants in your database, you will enjoy unparalleled functionality with your constants using this data type.
  • Classes are what makes your app sizzle. If you’re not using classes than you’re not tapping into the best that Access has to offer, period. We will discuss what the classes are and will provide you with some great examples.

When and Where

There are two ways you can participate:

  • In person: Go to CAUG.com and email Kevin Anderson to get on the guest list.
  • Via Web: At 5:45 PM Central Standard Time on January 26th I’ll start the web conference, join.me/accessexperts, please plan on arriving before 6 PM so we can get you setup and working before the show. You can reach me via email or chat by using the join.me software if you’re having problems connecting to the web conference.

Don’t miss out on this great opportunity to learn more and expand on your Access skills!

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

 
6

How to save your SharePoint password in Windows

Posted by Ben Clothier on January 18, 2012 in Access Help, Access Web Database, SharePoint

A poster asked me a wonderful question: “How do I get Access [linked to SharePoint] to remember my login credentials so I don’t have to login everytime?” The answer to the question isn’t simple as it should be and hence, I felt an article on the subject would be helpful for those who want to automate logging.

For people who have an account with Office365, remembering the account password is quite straightforward. Office365 has their own custom security and thus we get a different login form when we open an Access database that depends on Office365 (whether as a published web database or containing linked tables to lists on the site):

As you can see on the screenshot, you can simply check the checkboxes, “Remember Me” and “Keep me signed in” if you don’t want to get prompted for password again. Simple!

Great! But I’m not on Office365…

When you’re using a SharePoint server that is maybe hosted somewhere else or on your network, and SharePoint is using its default setting, you’ll see a login like this:

(on Windows XP)

(on Windows 7)

The important thing to note here is that it’s not an Access thing. Access is basically calling Internet Explorer to authenticate for you. So it’s the Internet Explorer setting what we want to work with, and hence why you wouldn’t find anything to do with managing authentication within Access.

“Remember Me” doesn’t mean what it says

A more accurate statement would be probably “Remember Me, if you’re allowed to”. People are understandably frustrated when they check the box then next time they still get challenged. What’s going on? Well, in name of security, Internet Explorer may not be permitted to save the password unless you make some changes to the settings. By default, it tries to automatically authenicate for Intranet, which isn’t appropriate in this case. Therefore you need to change it so that it uses username/password. To do this, we start with….

Start Menu -> Control Panel -> Internet Options:

On the dialog, select Trusted sites zone, then click the Sites button

On the dialog, clear the checkbox for “Require server verification…” and then enter the host name of your SharePoint server. You don’t need to enter the full address of where your Access application is published to or linked to, just the base address. So if your Access application has a SharePoint list linked to http://mySharePoint.local/sites/MySite, then you would just enter “mySharePoint.local”

Click “Close” to return to Internet Properties dialog, then click Custom Level.

Scroll all way to the bottom then select “Authenicate with current username and password”

Once you’re set the radio button, click OK, then OK again on Internet Properties dialog to close both dialogs and save the changes. Back on Control Panel, we go to User Account.

Note: From this point on, the steps diverge between Windows XP and Windows 7 — for those on Windows 7 scroll down further to see the steps for Windows 7.

On the Advanced tab, click Manage Passwords

Click the “Add” button.

On this page, enter the same server host name that you entered for sites dialog previously, then the username and password you use to log in to your SharePoint host.

Click OK, then Close, then OK. You’re done with establishing the identity. You can now go to your Access application, login in then check the “Remember Me” this time and you won’t be challenged next time you run your Access application.

For Windows 7 users

As mentioned the last part of saving passwords diverge when you get into User Accounts. In User Accounts, you would select Manage Credentials.

On Credential Manager, select “Add Generic Credentials”

You would then enter the same hostname of your SharePoint server that you entered in Sites for Trusted Sites and your username/password you use to log in.

At this point, you can now run your Access Application, log in and check the “Remember Me” and it’ll actually remember next time you run your Access application.

Caveats

The steps I have outlined here are essentially the same steps that one would take to remember the login for any other SharePoint function. If you have your SharePoint server hosted somewhere other than Office365, they will likely have specific instructions that may differ slightly in allowing you to use the “Remember Me” functionality. Thus, it may be good idea to consult with them first. Searching using “Remember Me SharePoint Internet Explorer” keywords usually will yield good results.

Furthermore, if you google a bit on the subject, you’ll find different methodologies. Some may recommend using Intranet zone instead of Trusted Sites zone in the Internet properties – there is indeed a subtle difference in behaviors between those two zones, so if you find that the above instructions does not work for you, give Intranet zone a try. This appears to be a version-specific issue for the Internet Explorer as well.

Can I use VBA to automate this?

This isn’t a final pronunciation but my guts says “No” on this subject. As mentioned, this is an Internet Explorer thing and Access needs to get the token after authentication, so while I believe there may be APIs that could allow you to simulate logging in, you’d be faced with problem of feeding that token to Access. One could argue this is a good thing since it makes it less likely that you’ll be hijacked and logged into someone else’s site. After all, saving passwords are big security issues (e.g. it may mean someone could just waltz in, sit in any one of the workstation and they have access to the data). You could use the information above to at least get your users set-up at the installation time, so it’ll be an one time thing.

If the article has helped or didn’t work, by all means, let us know in comments below!

Ben Clothier

Ben Clothier is a Senior Access Developer at IT Impact, Inc., an Access MVP since 2009 and a SharePoint Technology Specialist. He has worked on business applications from a department's survey tracking to world-wide supply control database and in between. If he's not developing, he's probably reviewing or writing something about Access development! He recently co-authored Microsoft Access in SharePoint World. To learn more, visit AccessExperts.net for more details.

Website - More Posts

 
7

Create temp tables in Access from SQL Server tables

Posted by Juan Soto on January 10, 2012 in Access Help, SQL Server, VBA

If you’ve ever asked Access to do a join between a local Access table and SQL Server table (which is called a heterogeneous join) you may have experienced first hand how slow it can be to process results. The situation could be vastly superior if you can afford to download the SQL table as a temporary table to your Access front-end and then process the join. This post will provide you with an easy solution to download SQL Server data into Access using a subroutine you can call from code.

Pass Through Query + Make Table Query Combo (No Linked Table Approach)

There is no direct way to download SQL Server data into Access using code, you can’t use a ADODB recordset or command to download the data, since they only “see” the SQL Server side and don’t have exposure to your Access data. The technique I’m providing here will use a temporary pass-through query, then using it with a make table query to create the local Access table copy of your SQL data.

'Insert this constant in a public module:
Public Const conConnectionQry As String = _
  "ODBC;DRIVER={SQL Server};SERVER=YourServerIPAddressGoesHere;" & _
  "UID=YourUserIDGoesHere;PWD=DittoPassWord;" & _
  "DATABASE=NameOfYourSQLServerDatabase"

Public Sub CreateLocalSQLTable(  _
  strTable As String, _
  strSQL As String, _
  Optional bolExportExcel As Boolean _
)
 Dim qdf As DAO.QueryDef
 Dim strQuery As String

10   On Error GoTo ErrorHandler
20   strQuery = "qryTemp"
30   DoCmd.Close acTable, strTable

40   DoCmd.DeleteObject acQuery, strQuery
50   DoCmd.DeleteObject acTable, strTable
60   Set qdf = CurrentDb.CreateQueryDef(strQuery)
70   With qdf
80     .Connect = conConnectionQry
90     .SQL = strSQL
100    .Close
110 End With
120 strSQL = "Select * INTO " & strTable & " FROM " & strQuery
130 CurrentDb.Execute strSQL
140 DoCmd.DeleteObject acQuery, strQuery
150 If bolExportExcel Then
      Dim strFile As String
160   strFile = CurrentProject.Path & "\" & strTable & _
                Month(Date) & Day(Date) & Year(Date)
170   If Dir(strFile) <> "" Then
180     Kill strFile
190   End If
200   MsgBox "Table " & strTable & " is ready for export to Excel"
202   DoCmd.TransferSpreadsheet acExport, , strTable, strFile, True
204   FollowHyperlink strFile & ".xlsx"
210 End If

ExitProcedure:
220 Set qdf = Nothing
230 Exit Sub

ErrorHandler:
240 Select Case Err.Number
      Case 3376, 3010, 7874, 2059
250     Resume Next
260   Case Else
270     MsgBox Err.Description, vbInformation, "Error"
280     GoTo ExitProcedure
290 End Select
End Sub

The procedure takes three arguments:

  • strTable: Name you wish to use for your local Access table
  • strSQL: SQL statement used to retrieve data from SQL server. You can therefore extract multi-table joins into a local Access table.
  • bolExportExcel: Boolean variable you pass-along if you wish to also extract the data into Excel

Example 1: Extract one table from SQL Server called tblCustomers

CreateLocalSQLTable "tblCustomers_SQL", "Select * from tblCustomers"

Notice how I appended the _SQL to my local Access table name. I will later delete all _SQL tables on program exit.

Example 2: Multi-table join extract

CreateLocalSQLTable "tblCustomers_SQL", "Select CustomerID, CustomerName, CustomerStatus from tblCustomers Inner Join tblCustomerStatus On tblCustomers.CustomerStatusID = tblCustomerStatus.CustomerStatusID", True

In the second example the code will also launch Excel with the extracted data, allowing my customer easy Access to data from SQL Server without the use of ODBC in Excel.

Add indexes and primary keys if needed

Once you’ve downloaded the data you may have a need to add indexes or primary keys to your local copy of the table, click here for a post that will walk you through that using Alter SQL commands in Access.

Another Approach using Linked Tables

If you have the SQL Server table already linked to your Access front-end you can extract the data using this procedure:

Public Sub CopyTableLocally(strTable As String)
    Dim strSQL As String

10  On Error GoTo CopyTableLocally_Error
20  Application.Echo True, "Working on table " & strTable
30  DoCmd.DeleteObject acTable, strTable & "_SQL"
40  strSQL = "Select * Into " & strTable & "_SQL From " & strTable
50  CurrentDb.Execute strSQL
ResumeExit:
60  On Error GoTo 0
70  Exit Sub
CopyTableLocally_Error:
80  Select Case Err.Number
      Case 3376, 3010, 7874, 2059 'Trying to delete an object that does not exist, continue
90      Resume Next
100   Case Else
110    MsgBox "Error " & Err.Number & " (" & Err.Description & _
              ") in procedure CopyTableLocally of Module mdlGeneral"
120    Resume ResumeExit
130 End Select
140 Resume ResumeXit
End Sub

 

Some Caveats

  • Don’t download too much data. There’s a good reason your data is on SQL Server. Pulling large amount of data only eats up network traffic and may cause contention issues or even deadlocks. I usually use this technique for small reference tables that I later use in a all local joins. If your data is small and the data rarely changes in the table you’re downloading than this code is for you.
  • Beware of file bloating: Ideally you should keep your temp tables in a separate Access file, otherwise your front-end may start getting pretty large and require frequent compacting to slim it back down.

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

 
0

Thinking about hosting your SQL Server database on the web?

Posted by Juan Soto on December 27, 2011 in SQL Server

Hosting on the web is a hit or miss, you will find a wide range of providers, from dirt cheap hosting companies that will lump you in with hundreds of other databases, to premier firms that will rent you a server all for your self.

Many traps to avoid

If you’re not careful you may end up with a host of problems: Record locks preventing users from committing changes, speed issues, bottlenecks, and records you can’t edit, etc.

SQL Server Hosting for Access

We love the combination of SQL Server and Microsoft Access, it is an unbeatable combo, and if you need it to work on the web then you can’t go wrong with hosting your SQL Server database in the cloud, it’s fast, reliable and secure. If done right it may even be faster using the cloud than using a Access backend!

Given that most Access + SQL solutions are relatively small databases, you want to host your data with a reliable provider and someone who can provide you with specialized support to get your app on the web.

The Solution: Using AccessExperts.net hosting

If you are a frequent reader of this blog you already know the wealth of knowledge available here, it’s a treasure trove of techniques and advise to get your SQL Database to the web and all free. But if you host your database with us you will get much more:

  1. SQL Server 2008 R2 Hosting
  2. 15 Gigabytes of storage
  3. Encrypted communications between Access and SQL Server
  4. Encrypted file storage of your data
  5. Unlimited users
  6. Run jobs for a small fee
  7. Hourly and nightly backups
  8. Best of all: Personalized coaching to get your database on the web!

We want you to succeed – Free Coaching

Get one on one coaching every step of the way as you design, test, and deploy your database to the web, no other hosting firm offers more.

All of this for just $39 per month! And if you prepay for one year you willget one month free.

But wait! There’s one more thing…

FREE live tech support: we will assist you in trouble shooting connections between Access and your SQL database. Don’t fret on why your database is not connecting to the server, a solution is just one phone call away.

Ready to get started? Give us a ring at 773.809.5456 or contact us here.

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

 
5

Our favorite online small business tools

Posted by Juan Soto on December 21, 2011 in Access Help

Our Access/SQL Server/SharePoint practice benefits from great tools on the web, some free and some not, and I’d like to share our experiences with you.

LogMeIn.com (Free) and LogMeIn Ignition (Subscription) for Windows

We usually use the Remote Desktop Connection when working with our client’s systems, but sometimes that’s not an option, so we ask them to install LogMeIn.com, which is free. The product has gotten better over the years and now offers support for multiple monitors, local printing and shared clipboards among other features. They offer a subscription product called LogMeIn Ignition for Windows, which allows us to easily login to all of our client computers without having to go to LogMeIn.com, definitively worth the price if you plan on supporting many people this way.

LogMeIn Ignition for iOS ($29.99)

I can’t tell you how many times I’ve had to pull over and help a client using my iPhone or iPad using the LogMeIn app. It’s not cheap at $29.99 compared to other $0.99 apps, but when you support clients for a living it’s indispensable. Buy it once and use it on all your IOS devices.

Join.Me (Free)

Our favorite support tool is now Join.me, it’s free and it’s also from LogMeIn.com but unlike LogMeIn it does not install a program for the viewer and it’s a small executable for the presenter. It’s what we use for all of our web conferences and has a free iOS app to boot. One big plus: It works even if both the presenter and the observer are both using Remote Desktop Connections, something we can’t say for other support tools out there. I’ve used the iOS app over 3G with the VOIP feature to speak with the client and it ran with no issue, you owe yourself to check this one out.

Toggl.com (Free)

We make our living with hourly consulting so it’s imperative we keep track of our time and it doesn’t get any easier with the free Toggl.com We keep track by project and client and best of all it keeps going even if we get the blue screen of death.

DropBox.com (Free)

We used to share large files using FTP, which was not intuitive for our customers. No more! Now we use DropBox for sharing files with clients and among ourselves, it doesn’t get any easier or more powerful than this. We can share a single folder with a client and anything we place in there gets automatically synced with them. We sprung for the $9.99 monthly plan since we also use it to share our code and store our server backups. We will most likely get the team package for $799 and get 1,000 GB of space, which we will use to backup our SQL Server databases over the web.

MozyPro.com (Subscription)

If you’re still backing up with tapes or backing up to a local drive you’re asking for trouble. How are you going to recover if there’s a fire, robbery or equipment failure? Backups over the web are the only way to go for piece of mind. I use the cheaper Mozy.com for my home PC and MozyPro.com for our servers. Space is dirt cheap at $0.50 per GB per month.

QuickBooks Online (qbo.intuit.com) Starts at $12.95/month

We have run our business on Quickbooks since 1994, but I got tired of the constant upgrade cycle, when Intuit introduced an online version we sprung at the chance to take our accounting to the next level. We signed up for the payroll service at Costco, (more on that below), and get further discounts through our accountant, (if they are not signed up get them to do so for the great discount). You may also get by with the minimum three logins, since your Accountant is free and so are any employees/consultants who are only entering their billing time. They use Toggl to track time and enter the entries into QB Online.

Costco for Business

By far one of our best investments has been the Costco business membership. We get our business checks, payroll processing and a big fat check once a year from them since we buy as much as we can there.

Bank of America Credit Card Processing

If you don’t take credit cards you’re missing out on improved cash flow and making it easy for clients to pay you. Most of our business is now done through credit cards. Since we bank at BofA the funds are deposited the next business day after the transaction. Do exhaustive research before picking a credit card processor for the best rates. Since we do most of our business remotely, we opted for the mail order rate and the online credit card processing, allowing us to take cards anywhere in the world without a terminal. (Processing is done through MyVirtualMerchant.com)

WordPress Blogging Software

We LOVE WordPress and will be switching all of our web properties over to this great technology. The extensions, easy to use software and powerful features make it a no-brainer for us. I’ll be blogging about our setup in a future post, but if you are considering this for your firm we do offer hosting for WordPress at only $125/year. Contact us for more details.

 

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

 
2

New book for Access Web Database and SharePoint now available!

Posted by Ben Clothier on December 17, 2011 in Access Web Database, SharePoint, VBA

As Juan may have mentioned earlier, I had been working with two other MVPs, Tim Runcie and George Hepworth in producing the first of its kind, a book dedicated to using Access with SharePoint. The book can be bought online at the Advisicon store.

If you’re wanting to learn more about the capabilities and limitations of Access and SharePoint, this book is a wonderful starting point in getting the fundamentals as well discussion on what’s going on under the hood. It will help you make informed design decisions whether you build an Access web database or use traditional Access application linked to SharePoint lists.

Click the image to purchase the book.

Sale: $10 off to first ten buyers!

If you use the coupon “save10bucks” and you’re one of first ten buyers, you can save $10 off the book’s price!

If you do buy the book, please let the authors know how it has helped!

Ben Clothier

Ben Clothier is a Senior Access Developer at IT Impact, Inc., an Access MVP since 2009 and a SharePoint Technology Specialist. He has worked on business applications from a department's survey tracking to world-wide supply control database and in between. If he's not developing, he's probably reviewing or writing something about Access development! He recently co-authored Microsoft Access in SharePoint World. To learn more, visit AccessExperts.net for more details.

Website - More Posts

 
0

How to work offline with SharePoint and Access 2010

Posted by Ben Clothier on December 8, 2011 in Access Help, Access Web Database, SharePoint, VBA

One advantage a SharePoint list has over any ODBC data source is that Access can disconnect and re-connect and synchronize the local edits back to the server fairly seamlessly. It also provides a friendly conflict resolution management, all out of the box. This is available whether you’re using a traditional Access database linking a SharePoint list or using a web-enabled database in an Access client.

2010 is much better at handling breakups

There is no built-in method to work offline as there was in 2007. Instead, in 2010, whenever a network connection was dropped, the application will automatically go into a disconnected mode. The user can see all that is going on in the status bar that may appear:

Status Bar indicating that some tables are disconnected

When the network connection is restored, the user will see a message bar with a button to reconnect and thus return to online mode:
Message bar prompting for synchronization

If the user clicks the Synchronize button, the offline edits are immediately reconciled with the server, but the user can also ignore that message and continue working offline, synchronizing at a later time.

This is an improvement over 2007 where a dropped connection would be disastrous to the session. To avoid the issue, you had to explicitly toggle offline mode while you’re connected. Behind the scenes, all tables are opened & cached locally using XML. Clearly, that wasn’t too practical if you couldn’t anticipate when the network would degrade or get dropped, and thankfully it’s been rectified in 2010.

Great! But I still want to disconnect and batch my edits!

Fortunately, there is an approach to doing this. Using Internet Explorer, you can go to File -> Work Offline.
Select Work Offline in Internet Explorer to block SharePoint synchronization

That blocks all network activity, including a running Access instance that has a link to a SharePoint list. Once you’ve dirtied a single record, you can then restore network activity. If there were no edits during the disconnection and network is restored, Access will automatically reconnect without any prompt. However, if there are any edits, Access will inform the user that the network is restored and the table can be reconnected. Thus, the network only needs to be disconnected long enough for you to dirty a record, then get back online immediately afterward. Obviously, that would not work very well if you had some kind of open network session such as downloads, FTP, remote desktop connection and so forth. If that is a concern, you may need to plan and train your users to work with this consideration.

Easily work offline

With the caveats in mind, it is possible to automate the “Work Offline” functionality and interrupt the network only briefly, long enough to dirty a single record which is all you need to be able to work offline. Even though when you’re back online and you’re editing different tables, those edits in all tables are all batched and won’t be committed until you choose to synchronize.

Whenever you want to enter the offline mode, you only need to call ToggleOfflineMode. It’ll then interrupt the network by making a API call that’s equivalent to selecting “Work Offline” in the Internet Explorer, dirty a record, then call the API again to restore the internet connectivity. To make this possible you need two things; a linked SharePoint list that you can use as a target to dirty. It doesn’t have to be one of your actual data tables and you could even create a stand alone table with one column (besides the required ID column) and one row. The second thing is of course the code to call the API. Simply copy the code at end of this post & insert into a new blank module.

Errors to watch out for

Because it may take some time between the actual disconnection and Access to detect that network is lost, there may be errors if user immediately moves on to other tasks after disconnecting. You can trap for those errors in your usual error handling and typically re-attempt the same operation. You may get either error number 3907 or 3918. 3918 typically can be resolved by waiting a bit and trying again. In my experimentations, if you try to handle the error in a VBA error handler, it will get stuck in an infinite loop and DoEvents doesn’t allow Access to detect the state change. Thus, best thing to do is to simply show a message box telling user to try again and have the user re-initiate the action. This way, Access will be able to notice the state change and respond accordingly. The 3907 can be treated like 3918 with a caveat – if you decide you want to be offline for an extended period of time, the 3907 error can not be resolved until connection is restored. This should not be an issue with the code given which only disconnects for a brief moment.

Reconnecting

When you’re ready to reconnect and therefore synchronize the data changes, it can be as simple as training the user to click the “Synchronize” button on the Message bar or via backstage (File -> Reconnect All Tables). If you’re using a web database and you have it opened in Access, you can also use this VBA command to force a synchronization:

DoCmd.RunCommand acCmdSyncWebApplication

Keeping in mind that this has the side effect of synchronizing any design changes in addition to data changes. If you need to call the above VBA from a web object, you can use IsClient() to conditionally access the VBA or disable the functionality when it’s opened in a web browser where it’s not relevant.

But if you are using a regular Access database with linked SharePoint lists, there is currently no programmatic method to replicate the “Reconnect Tables” functionality, and therefore training users is the only way. If users have dismissed the Message Bar, they can still synchronize by either clicking on the status bar or going to Backstage.
Reconnect Button in the Backstage

Two more considerations

If you allow users to edit a large amount of records offline, you may have to deal with record conflicts with other connected users. Also, if it takes too long to synchronize, you may get timed out. Thus, I encourage you to test your specific environment and determine whether it will work well and how many records you can reliably synchronize at a time.

One more alternative

Though Access 2010 caching is significantly improved, it comes with less control. If that is not acceptable, an option is to turn off 2010 caching and therefore use the caching that was used in Access 2007. You can set this via Access’ Options shown here.

Disabling 2010 format caching and reverting to 2007 style caching

 

The difference is that you’ll be using XML to store the cached data rather than a Jet table, which has some performance ramifications as Access has to wade through the XML to satisfy your data requests. One upside: you get programmatical control, typically via RunCommand constants such as acCmdSynchronize and acCmdToggleOffline.

If you’ve found this code helpful or run into issues, please leave a comment and let us know about it!

Option Compare Database
Option Explicit

'IMPORTANT: The table and field must exist or you may rename
'           to one of your tables designated for sole purpose
'           of prevent automatic reconnection by dirtying a
'           record
Const strMyTable As String = "tblDummy"
Const strMyField As String = "Dummy"

Private Const INTERNET_OPTION_CONNECTED_STATE = &H32
Private Const INTERNET_STATE_CONNECTED = &H1
Private Const INTERNET_STATE_DISCONNECTED = &H2
Private Const INTERNET_STATE_DISCONNECTED_BY_USER = &H10
'Private Const INTERNET_STATE_IDLE = &H100
'Private Const INTERNET_STATE_BUSY = &H200
Private Const ISO_FORCE_DISCONNECTED = &H1

Private Type INTERNET_CONNECTED_INFO
    dwConnectedState As Long
    dwFlags As Long
End Type

'NOTE: Using VBA7 declaration (incompatible with older Access)
Private Declare PtrSafe Function InternetSetOption _
Lib "wininet.dll" _
Alias "InternetSetOptionA" ( _
    ByVal hInternet As LongPtr, _
    ByVal dwOption As Long, _
    lpBuffer As INTERNET_CONNECTED_INFO, _
    ByVal dwBufferLength As Long _
) As Boolean

'NOTE: Using VBA7 declaration (incompatible with older Access)
Private Declare PtrSafe Function InternetQueryOptions _
Lib "wininet.dll" _
Alias "InternetQueryOptionA" ( _
    ByVal hInternet As LongPtr, _
    ByVal dwOption As Long, _
    lpBuffer As Any, _
    lpdwBufferLength As LongPtr _
) As Boolean

Public Property Get IsOffline() As Boolean
On Error GoTo ErrHandler
    Dim l As Long

    If InternetQueryOptions( _
        &H0, INTERNET_OPTION_CONNECTED_STATE, l, 4 _
    ) Then
        IsOffline = ( _
            INTERNET_STATE_DISCONNECTED = ( _
                l And INTERNET_STATE_DISCONNECTED _
            ) _
        )
    End If

ExitProc:
    On Error Resume Next
    Exit Property
ErrHandler:
    Select Case Err.Number
        Case Else
            MsgBox _
                "Error " & Err.Number & ": " & Err.Description, _
                vbCritical, "Unexpected error"
    End Select
    Resume ExitProc
    Resume
End Property

Private Function SetOfflineMode( _
    ByVal Offline As Boolean _
) As Boolean
On Error GoTo ErrHandler
    Dim CI As INTERNET_CONNECTED_INFO

    If Offline Then
        CI.dwConnectedState = INTERNET_STATE_DISCONNECTED_BY_USER
        CI.dwFlags = ISO_FORCE_DISCONNECTED
    Else
        CI.dwConnectedState = INTERNET_STATE_CONNECTED
    End If
    SetOfflineMode = InternetSetOption( _
        0&, INTERNET_OPTION_CONNECTED_STATE, CI, LenB(CI) _
    )

ExitProc:
    On Error Resume Next
    Exit Function
ErrHandler:
    Select Case Err.Number
        Case Else
            MsgBox _
                "Error " & Err.Number & ": " & Err.Description, _
                vbCritical, "Unexpected error"
    End Select
    Resume ExitProc
    Resume
End Function

Public Sub ToggleOfflineMode()
On Error GoTo ErrHandler
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef

    Set db = CurrentDb

    If IsOffline Then
        SetOfflineMode False
    End If
    With db.OpenRecordset( _
        "SELECT * FROM [" & strMyTable & "]", _
        dbOpenDynaset _
    )
        'The table is cached
        SetOfflineMode True
        .Edit
        .Fields(strMyField).Value = .Fields(strMyField).Value
        .Update
    End With

ExitProc:
    On Error Resume Next
        'ensures internet connection is always restored when leaving
        SetOfflineMode False
        Set tdf = Nothing
        Set db = Nothing
    Exit Sub
ErrHandler:
    Select Case Err.Number
        Case Else
            MsgBox _
                "Error " & Err.Number & ": " & Err.Description, _
                vbCritical, "Unexpected error"
    End Select
    Resume ExitProc
    Resume
End Sub

Ben Clothier

Ben Clothier is a Senior Access Developer at IT Impact, Inc., an Access MVP since 2009 and a SharePoint Technology Specialist. He has worked on business applications from a department's survey tracking to world-wide supply control database and in between. If he's not developing, he's probably reviewing or writing something about Access development! He recently co-authored Microsoft Access in SharePoint World. To learn more, visit AccessExperts.net for more details.

Website - More Posts

 
0

Microsoft’s Official Response to ADO mess…

Posted by Juan Soto on December 5, 2011 in Access Help

Those of you caught with the Windows 7 SP1 bug that rendered your development computer useless for Access 2007, (including yours truly), can read up on the official Microsoft response to the issue here:

http://blogs.msdn.com/b/psssql/archive/2011/10/03/yes-we-made-a-mistake-and-are-finally-going-to-fix-it.aspx

Kudos to the team for owning up to the issue, but I would have loved to see a faster response.

DRASTICALLY UNDERESTIMATING…

This statement really caught my eye:

"Unfortunately, we drastically underestimated the number of customers who were recompiling ADO applications on Windows 7 SP1. Even worse, when I say drastically, I really mean DRASTICALLY."

 

Why was the large amount of calls a surprise for Microsoft’s support arm?

Are we few or are we many?

It goes to the heart of the issue with Microsoft’s outreach to the Access developer community, and therefore their lack of understanding on how big it is. I know they have a Microsoft Access development page and they have a Developer’s forum too but I believe they can do more, but am not sure on the return on investment. When I see the reaction above it gives me hope that we are many, but are we growing as a group, or diminishing?

Access Experts Ready to Help

What can Microsoft do to encourage Access development

You may wonder if they do want to encourage development in the first place…and I think they do, otherwise, why develop a great macro tool for Access 2010? The fact is all professional Access developers use mostly VBA, but at least it’s a commitment to programming in the platform. I would love to see a worldwide development conference just for Access developers, dedicated resources to the community and a path to partnership via Access development.

My personal mission: Grow more Access developers

I decided to make Access my focus and not .Net for reasons I’ve explained before, and now I’m adding a new mission, “helping others become great Access developers”. The more the merrier, there is so much work for Access out there, enough for all of us and then some. We need to reach a critical mass so that we can come together and become a force. The PAUG conference is a great start and I hope you can join us next year.

If you wish to join me in this effort then I encourage you to share your code, techniques and passion with us online, providing resources for those who wish to pursue Access development as a career choice.

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

 
0

Using control tip property to display real time information

Posted by Juan Soto on November 29, 2011 in Access Help

I was selected to be a guest blogger on the official Microsoft Access blog! You can read the article here:

http://blogs.office.com/b/microsoft-access/archive/2011/11/28/display-real-time-information-with-the-controltip-property.aspx

Please read and come back here for some final thoughts on the technique.

Another alternative: DAO

When I wrote the guest post I automatically selected ADODB since that’s what I use almost always in my code. Here’s the same concept using DAO:

Private Sub OrderStatus_MouseMove( _
          Button As Integer, _
          Shift As Integer, _
          X As Single, _
          Y As Single _
)          
          Dim strSQL As String
          Dim rst As DAO.Recordset
          Dim db  As DAO.Database
10        If IsNull(Me.OrderID) Or Me.OrderID = "" Then
20            Exit Sub
30        End If
32        strSQL = "Select ItemNum from tblOrderItems Where OrderID = " & Me.OrderID
33      Set db = CurrentDB
34      Set rs = db.OpenRecordset(strSQL)
60        With rs
70            If .RecordCount > 0 Then
80                strSQL = ""
90                Do While .EOF = False
100                   strSQL = strSQL & !ItemNum & vbCrLf
110                   .MoveNext
120               Loop
130           End If
140       End With
150       Me.OrderStatus.ControlTipText = strSQL
160       Set rs = Nothing
End Sub

 

Persistent Recordset

If you find yourself constantly opening and closing the recordset, you can choose to create a module level variable, move out the line 30-32 into form’s load or current event and not closing the recordset by commenting out line 160 above.  If you do go down this route then you would need to retrieve all related records in one trip. You also may want to open the recordset as a snapshot-type recordset to ensure the request is pulled only once. If it’s a lot of records in memory it may not be worth it.

After all these years I’m continually amazed at the capabilities of Access and how we can stretch the envelope of what can be done.

Juan Soto

Juan Soto is a Senior Access Developer at IT Impact Inc. and a Microsoft Access MVP. He specializes in Access with SQL Server databases. His passion for Access has led him to helping a wide range of businesses in helping them establish a secure, stable and efficient environment with SQL Server. He's a frequent speaker at Access user groups nationwide and recently spoke at the Orange County SQL Saturday # 73. To learn more about Juan, please visit his site: AccessExperts.net or blog: AccessExperts.net/blog. If you wish to have Juan speak at your next group meeting you can contact him here: http://accessexperts.net/contact_us.php

Website - More Posts

Copyright © 1969-2012 Microsoft Access with SQL Server Blog All rights reserved.
Desk Mess Mirrored version 1.9 theme from BuyNowShop.com.