accvbalearner
Registered User.
- Local time
- Today, 11:11
- Joined
- Jan 3, 2013
- Messages
- 42
Hi all,
:banghead: Stuck again and everyone here is so helpful!
Today I am trying to retrieve a subform's name so that I can incorporate it into a piece of code, but I am not having any luck after searching through the forum.
I have established a variable like this:
Dim currentFormName As Form
Set currentFormName = Screen.ActiveForm
fmName = currentFormName.Name
to get the name of the Active Form so that I can return to it after another form closes.
Now what I would like to do is the same thing for a subform but I can't figure out how to create the reference.
The code below is on the lost focus event for a field in a form. I have seven other forms that are similar but get data to/from from different tables. What I would like to do is have one set of code that will get the name of the recordsource for the form and the name of the subform so that the code can just be copied and pasted in to each lost focus event on the seven forms, or made into a standard module that the lost focus event will refer to when running.
Any help would be much appreciated!
:banghead: Stuck again and everyone here is so helpful!
Today I am trying to retrieve a subform's name so that I can incorporate it into a piece of code, but I am not having any luck after searching through the forum.
I have established a variable like this:
Dim currentFormName As Form
Set currentFormName = Screen.ActiveForm
fmName = currentFormName.Name
to get the name of the Active Form so that I can return to it after another form closes.
Now what I would like to do is the same thing for a subform but I can't figure out how to create the reference.
The code below is on the lost focus event for a field in a form. I have seven other forms that are similar but get data to/from from different tables. What I would like to do is have one set of code that will get the name of the recordsource for the form and the name of the subform so that the code can just be copied and pasted in to each lost focus event on the seven forms, or made into a standard module that the lost focus event will refer to when running.
Code:
Private Sub ActCode_LostFocus()
'This will determine if the Field APCode will be a duplicate
'based on the Facility and System Chosen. It should prevent
'Duplicate Systems from being created for the same facility.
Dim strSys As String
Dim strFac As String
Dim recSrc As String 'Used for Recordsource to Filter
Dim subFrm As SubForm 'Used for Name of Subform
Dim sfmName As String
Set subFrm = Screen.ActiveForm.Form.Name
sfmName = subFrm
MsgBox ("Name of Subform is : " & sfmName)
'This will determine the type of filter to use on F1x-Subform
'If ActCode is blank, but Facility isn't then it filters F1x
'for Facility only, otherwise it will clear the filter or run
'a filter if both are not null.
recSrc = Me.RecordSource
If IsNull(Me.ActCode) And Not IsNull(Me.Facility) Then
MsgBox ("Statement will look like this to filter: [PlantCode] = '" & Me.Facility & "'")
Me.sfmName.Form.Filter = "[PlantCode] = '" & Me.Facility & "'"
Me.sfmName.Form.FilterOn = True
Else
If IsNull(Me.ActCode) And IsNull(Me.Facility) Then
Me.sfmName.Form.FilterOn = False
Else
strAC = Me.ActCode
strFac = Me.Facility
strFP = strFac & strAC
'MsgBox ("Combined Code is " & strFP)
If Not IsNull(DLookup("[APCode]", recSrce, "[APCode] = '" & strFP & "'")) Then
MsgBox "The Area Code you have entered will create a duplicate area for the facility." & vbCrLf & "Here is the similar record."
Me.sfmName.Form.Filter = "[ActCode] = '" & strAC & "' AND " & "[PlantCode] = '" & strFac & "'"
Me.sfmName.Form.FilterOn = True
End If
End If
End If
End Sub
Any help would be much appreciated!
Last edited by a moderator: