Hope everyone is well.
I have something that is stumping me.
I have a table that has every Object and Control in my database. I am using it to run some code that will change all the visible labels to Russian.
I am stuck on the Sql statement that will query a Form and a Control by its value. For example, the code will run through a recordset of the table and get the Form and Control name, then it is supposed to create another recordset to find the matching Form name and Control name.
Here's the code and where it errors:
Public Function ImportRussian()
On Error GoTo Err_Handler
Dim rst As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim obj As AccessObject
Dim frm As Form
Dim ctl As Control
Dim strObjectName As String
Dim strParentObject As String
Dim strSQL As String
Dim strSQL2 As String
strSQL = "SELECT * FROM tblLabelList ORDER BY LabelID ASC"
Set rst = CurrentDb.OpenRecordset(strSQL)
' Loop through all the forms and open them in design view.
For Each obj In CurrentProject.AllForms
strParentObject = obj.Name
DoCmd.OpenForm strParentObject, acDesign
Set frm = Forms(strParentObject)
' Loop through all the controls on the form.
For Each ctl In frm.Controls
strObjectName = ctl.Name
'Here's where I can not get the Syntax right....
strSQL2 = "SELECT * FROM tblLabelList WHERE [ParentObject]= " & obj.Name & " And [ObjectName]= " & ctl.Name
'OR below, errors with "...too few parameters"
'strSQL2 = "SELECT * FROM tblLabelList WHERE tblLabelList.ParentObject = strParentObject AND tblLabelList.ObjectName = strObjectName"
Set rs2 = CurrentDb.OpenRecordset(strSQL2)
If Not rs2.EOF Then
ctl.Caption = rs2!ObjectCaption
DoCmd.Close acReport, strParentObject
On Error Resume Next
Set frm = Nothing
Set rpt = Nothing
MsgBox Err.Number & " " & Err.Description, vbCritical, "FillLabelList()"
Any help or direction would be appreciated!