'---------------------------------------------------------------------------------------
' Procedure : PutFormRecordSourcesInTable
' Author : Jack
' Date : 02/03/2014
' Purpose : Review all forms in this database; find recordsource for each.
' If no recordsource bypass the form.
' if recordsource is a Table/Query identify the table/query and fields.
' if recordsource is SQL, identify the SQL string.
'---------------------------------------------------------------------------------------
'
Sub PutFormRecordSourcesInTable()
Dim afrm As AccessObject
Dim frm As Access.Form
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Dim RecSourceType As String
Dim strSQL_Drop As String
Dim strSQL_Create As String
10 On Error Resume Next
20 Set Db = CurrentDb
'Delete existing copy of this table
30 strSQL_Drop = "DROP TABLE tblRecordSourceOfForms;"
40 DoCmd.RunSQL strSQL_Drop
50 On Error GoTo PutFormRecordSourcesInTable_Error
60 strSQL_Create = "CREATE TABLE tblRecordSourceOfForms" & _
" (form_name varchar(250), RecordSourceType varchar(20),RecordSourceText longtext,RecordedDate Date );"
70 Db.Execute strSQL_Create, dbFailOnError
80 DoEvents
90 Set rs = Db.OpenRecordset("tblRecordSourceOfForms")
100 For Each afrm In CurrentProject.AllForms
110 If Not afrm.IsLoaded Then DoCmd.OpenForm afrm.name, acDesign, , , , acHidden
120 If Len(Forms(afrm.name).RecordSource & "") = 0 Then
130 Debug.Print afrm.name & " -- " & "**NO ASSIGNED RECORDSOURCE**"
140 RecSourceType = "NONE"
150 ElseIf InStr(Trim(Forms(afrm.name).RecordSource), "SELECT ") > 0 Then
160 Debug.Print afrm.name & " -- " & " - SQL - " & Forms(afrm.name).RecordSource
170 RecSourceType = "SQL"
180 Else
190 Debug.Print afrm.name & " -- " & " - Table/Query - " & Forms(afrm.name).RecordSource
200 RecSourceType = "Table/Query"
210 End If
220 rs.AddNew
230 rs!form_name = afrm.name
240 rs!RecordSourceType = RecSourceType
250 rs!RecordSourceText = Trim(Forms(afrm.name).RecordSource)
260 rs!RecordedDate = Date
270 rs.Update
GetNext:
280 DoCmd.Close acForm, afrm.name
290 Next afrm
300 Debug.Print "Finished processing " & Now
310 rs.Close
320 On Error GoTo 0
330 Exit Sub
PutFormRecordSourcesInTable_Error:
340 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure PutFormRecordSourcesInTable of Module AWF_Related"
End Sub