Run Code to Update (1 Viewer)

Thumper75

Registered User.
Local time
Today, 06:02
Joined
Feb 6, 2017
Messages
37
Greetings Guru's
I have two forms that I am working with. The first is a Parent form. On the load event I have it check for records pertaining to a tail number and log number. That code works without fail each time and is listed below.

Code:
Private Sub Form_Load()

Dim t As String
Dim lp As String
Dim strWhere As String
Dim lngLen As Long 'long length
Dim rs As DAO.Recordset
Dim cnt As Long

MsgBox "The Code is running"

Me.Form.Filter = "(False)"
Me.FilterOn = True

If Not IsNull(Me.Parent.txt_tail.Value) Then
    t = Me.Parent.txt_tail.Value
    strWhere = strWhere & "([af_reg] = """ & t & """) AND "
    'MsgBox ("The tail number is " & t)
End If

If Not IsNull(Me.Parent.txt_lp.Value) Then
    lp = Me.Parent.txt_lp.Value
    strWhere = strWhere & "([Logpg] = """ & lp & """) AND "
End If

lngLen = Len(strWhere) - 5

If lngLen <= 0 Then
    Exit Sub
Else
    strWhere = Left$(strWhere, lngLen)
    Me.Filter = strWhere
    Me.FilterOn = True
    MsgBox "The Filter has been applied"
End If

If Not (Me.RecordsetClone.EOF Or Me.RecordsetClone.BOF) Then
    Me.RecordsetClone.MoveLast
    cnt = Me.RecordsetClone.RecordCount
    MsgBox "There are " & cnt & " records for the form"
End If

If cnt <= 0 Then
    MsgBox "The Tab is off"
    Me.Parent.tab_New_Prts.Visible = False
Else
    MsgBox "The Tab is On"
    Me.Parent.tab_New_Prts.Visible = True
    Me.Refresh
End If

'Me.RecordsetClone = Nothing


End Sub

From this form I have a button that opens a pop up form and allows me to order a new part. When I submit the data and close the form I would like to re-run the code above. I have tried Refresh, OnGotFocus and OnActive. In each the case the code fails to run.

Code:
Private Sub cmb_sub_Click()
'Dim args() As String

DoCmd.Save
DoCmd.Close
Forms(frm_NewPart_Mon).SetFocus

End Sub

Can anyone suggest an event or a way to fire the code?
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 07:02
Joined
Oct 17, 2012
Messages
3,276
If all you want to do is re-run the Form.Load event after the pop-up form closes, do the following:

Change your code that opens the pop-up to:
Code:
DoCmd.OpenForm "Stuff", , , , , acDialog
Call Form_Load
Make sure to add any other parameters you already use in the OpenForm command, but make sure you select acDialog as the 6th parameter.
acDialog means that the form is opened as modal and popup, and execution on the calling form is halted until the pop-up is closed. Once that happens, execution resumes.
 

Users who are viewing this thread

Top Bottom