{"id":41,"date":"2007-05-22T08:25:05","date_gmt":"2007-05-22T08:25:05","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=41"},"modified":"2007-05-22T08:25:05","modified_gmt":"2007-05-22T08:25:05","slug":"vba-excel-sql-ldap-and-the-like","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/","title":{"rendered":"VBA, Excel, SQL, LDAP and the like.."},"content":{"rendered":"<p>Well, it&#8217;s been a very busy week or so, I&#8217;ve really been burying my head into the Excel code thats going to form the backend of our application. Due to the nature of the data and the demands of the users, I have certain restrictions on the reference numbers that we&#8217;re using to track the items.<\/p>\n<p>To this end, I&#8217;ve created a back-end database sitting on the SQL server that Excel references directly using ADO to create new records, query the DB and also run a report or two.<\/p>\n<p>This is now in place and functioning nicely. The next step now is to tidy up the code in Excel, prior to porting it into the full Document Template that the users know and love. The key problem here is going to be the legacy code that exists within the template from a previous owner. (Note to all previous owners: DOCUMENT YOUR DAMN CODE PLEASE!!!!!!)<\/p>\n<p>The next step is also the thorny issue of Authentication. In order to keep the calls to LDAP down to a miniumum, I have created a start-up macro that checks for membership of aparticular AD group before the button that displays the Admin Control panel is made available.<\/p>\n<p>In order to make updating easier when moving from Dev to live, I&#8217;ve created a couple of constants to track the LDAP addresses.. These are concatenated within the application to created the full LDAP string.<\/p>\n<p><code>Public Const LDAP_addy As String = \"DC=department, DC=company, DC=com\"<br \/>\nPublic Const LDAP_SO_financials As String = \"CN=grp_SOfinancials, OU=MOSS2007, OU=Service Accounts, OU=Machine Services\"<br \/>\n<\/code><\/p>\n<blockquote><p>Note: The DSN details above have been changed, but basically represents the domain name department.company.com and then nested OU&#8217;s that end with a Security group.<\/p>\n<p>Machine Services<br \/>\n        -> Service Accounts<br \/>\n                      -> Moss 2007<br \/>\n                                -> grp_SOfinancials<\/p><\/blockquote>\n<p>We then check the current logged on username (<em>This is retrieved using advapi32.dll code found on the MSDN website.. e-mail me if you want more details..) <\/em> against the AD group<\/p>\n<p><code>database_permitted = IsMemberOf()<\/code><\/p>\n<p>database_permitted is then used to hide the Control Panel button on the front page of our Excel worksheet.<\/p>\n<p><code><br \/>\nFunction IsMemberOf() As Boolean<br \/>\n'Routine to check that username is a member of the group passed as a variable<br \/>\nDim strGrp As IADsGroup<br \/>\nDim strUser As IADsUser<br \/>\nDim LDAP_full, SamUser As String<br \/>\nDim UserSuccess As Boolean<br \/>\nUserSuccess = False<\/p>\n<p>On error goto cleanup<\/p>\n<p>'Connect to the AD using global LDAP string<br \/>\nLDAP_full = \"LDAP:\/\/\" & LDAP_SO_financials & \", \" & LDAP_addy<\/p>\n<p>Set strGrp = GetObject(LDAP_full)<br \/>\nFor Each strUser In strGrp.Members<br \/>\nSamUser = UCase(strUser.Get(\"sAMAccountName\"))<br \/>\nIf Current_User = SamUser Then<br \/>\nUserSuccess = True<br \/>\nEnd If<\/p>\n<p>Next<\/p>\n<p>'Drop LDAP connection<br \/>\nSet strGrp = Nothing<br \/>\nSet strUser = Nothing<\/p>\n<p>IsMemberOf = UserSuccess<\/p>\n<p>Exit Function<br \/>\ncleanup:<\/p>\n<p>If (Err.Number <> 0) Then<br \/>\nMsgBox (\"An error has occured with Active Directory. You're security information cannot be confirmed!\" & Err.Number)<br \/>\nEnd If<br \/>\nSet strGrp = Nothing<br \/>\nSet strUser = Nothing<br \/>\nIsMemberOf = UserSuccess<\/p>\n<p>End Function<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, it&#8217;s been a very busy week or so, I&#8217;ve really been burying my head into the Excel code thats going to form the backend of our application. Due to the nature of the data and the demands of the users, I have certain restrictions on the reference numbers that we&#8217;re using to track the &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[14,9,3,15,13,7],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>VBA, Excel, SQL, LDAP and the like.. - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VBA, Excel, SQL, LDAP and the like.. - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"Well, it&#8217;s been a very busy week or so, I&#8217;ve really been burying my head into the Excel code thats going to form the backend of our application. Due to the nature of the data and the demands of the users, I have certain restrictions on the reference numbers that we&#8217;re using to track the &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2007-05-22T08:25:05+00:00\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/\",\"url\":\"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/\",\"name\":\"VBA, Excel, SQL, LDAP and the like.. - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"datePublished\":\"2007-05-22T08:25:05+00:00\",\"dateModified\":\"2007-05-22T08:25:05+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"VBA, Excel, SQL, LDAP and the like.. - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/","og_locale":"en_US","og_type":"article","og_title":"VBA, Excel, SQL, LDAP and the like.. - Blog of an overweight SharePoint addict","og_description":"Well, it&#8217;s been a very busy week or so, I&#8217;ve really been burying my head into the Excel code thats going to form the backend of our application. Due to the nature of the data and the demands of the users, I have certain restrictions on the reference numbers that we&#8217;re using to track the &hellip; Continue reading","og_url":"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2007-05-22T08:25:05+00:00","author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/","url":"https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/","name":"VBA, Excel, SQL, LDAP and the like.. - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"datePublished":"2007-05-22T08:25:05+00:00","dateModified":"2007-05-22T08:25:05+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.myfatblog.co.uk\/index.php\/2007\/05\/vba-excel-sql-ldap-and-the-like\/"]}]},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":0,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}