[blue]Public Function TabIdxName(frmName As String, TabIdx As Integer) As String
Dim Msg As String, Style As Integer, Title As String
Dim frm As Form, ctl As Control, Found As String, flg As Boolean
Style = vbInformation + vbOKOnly
If FormExist(frmName) Then
If Not IsOpenForm(frmName) Then
DoCmd.OpenForm frmName, acDesign, , , , acHidden
DoEvents
flg = True
End If
Set frm = Forms(frmName)
For Each ctl In frm.Controls
If ctl.TabIndex = TabIdx Then
Found = ctl.Name
Exit For
End If
Next
If Found <> "" Then
tabidxfound = Found
Else
Msg = "Control Name not found or TabIdx too high!"
Title = "Control Not Found! . . ."
MsgBox mag, Style, Title
End If
If flg Then DoCmd.Close acForm, frmName, acSaveNo
Set frm = Nothing
Else
Msg = "Form not found or doesn't exist!"
Title = "Can't Find Form Error! . . ."
MsgBox Msg, Style, Title
End If
End Function
Public Function FormExist(frmName As String) As Boolean
Dim db As DAO.Database, rst As DAO.Recordset, SQL As String
Set db = CurrentDb
SQL = "SELECT Name, Type " & _
"FROM MSysObjects " & _
"WHERE ((Name='" & frmName & "') AND " & _
"(Type=-32768));"
Set rst = db.OpenRecordset(SQL, dbOpenDynaset)
If Not rst.BOF Then FormExist = True
Set rst = Nothing
Set db = Nothing
End Function
Function IsOpenForm(frmName As String) As Boolean
If CurrentProject.AllForms(frmName).IsLoaded Then
IsOpenForm = True
End If
End Function[/blue]