I recently took over a database in which the previous dba had set a number of table fields to act as lookup displaying combo boxes. This is a horrible thing to do, IMHO, and since users should never directly have access to tables, and should be working through forms, there is absolutely no reason for this in the first place. Now not wanting to have to go through hundreds of tables and countless fields resetting this property manually, I decided to write a simple function to perform this cleanup for me. Hopefully this might help someone else out with this issue.
'--------------------------------------------------------------------------------------- ' Procedure : RemoveAllTableLookupCboLst ' Author : Daniel Pineault, CARDA Consultants Inc. ' Website : http://www.cardaconsultants.com ' Purpose : Loops through all the tables in a database and removes/resets the Lookup ' Display Control property to reset it to a simple textbox rather than a ' combo box or listbox. Never needed as users should never access tables ' directly! ' Copyright : The following may be altered and reused as you wish so long as the ' copyright notice is left unchanged (including Author, Website and ' Copyright). It may not be sold/resold or reposted on other sites (links ' back to this site are allowed). ' ' Usage: ' ~~~~~~ ' Call RemoveAllTableLookupCboLst ' ' Revision History: ' Rev Date(yyyy/mm/dd) Description ' ************************************************************************************** ' 1 2013-May-17 Initial Release '--------------------------------------------------------------------------------------- Function RemoveAllTableLookupCboLst() As String On Error GoTo Error_Handler Dim db As DAO.Database Dim td As DAO.TableDefs Dim t As DAO.TableDef Dim fld As Field Set db = CurrentDb() Set td = db.TableDefs On Error Resume Next For Each t In td 'Loop through each table If Left(t.Name, 4) <> "MSys" Then 'Don't mess with system tables! For Each fld In t.Fields 'loop through each field fld.Properties("DisplayControl") = acTextBox Next fld End If Next t Error_Handler_Exit: On Error Resume Next Set td = Nothing Set db = Nothing Exit Function Error_Handler: MsgBox "The following error has occured." & vbCrLf & vbCrLf & _ "Error Number: " & Err.Number & vbCrLf & _ "Error Source: RemoveAllTableLookupCboLst" & vbCrLf & _ "Error Description: " & Err.Description, _ vbCritical, "An Error has Occured!" Resume Error_Handler_Exit End Function |


