Subform Refresh

  • Thread starter Thread starter rm
  • Start date Start date
R

rm

I have a main form (frmDO) with a subForm (frmDODetail) where the sub
control name is sfrmDODetail. The subform is a datasheet.

When I double click on sfrmDODetail and edit form is displayed
(frmEditDODetail).

When I save the changes in the edit form (frmEditDODetail) I want the
sub form (sfrmDODetail - frmDODetail) to display the edits/changes/
additions made by the user.

I have tried numerous different ways (many suggested in this group) to
make the sub form (sfrmDODetail - frmDODetail) requery. I have tried
Forms! etc, Dim frm as FORM_frmDODetail. I have spent 4 - 5 hours
trying every different combination. At one point I had a variation of
Forms! working. Then out of the blue the method no longer worked.

I am in the military - in Iraq. Three days ago I was laying in a 1
foot deep ditch with mortar rounds landing within a quarter mile of my
position. I am far more upset, frustrated about working with this
Microsoft Product!

Please help.
 
Thank you for the response. Now the situation is degrading. I am
seeing very odd behaivor. Before I move to the "edit" form, save the
changes, return to the main form, move next then move prev (or move
prev then move next) and see the changes. Now from time to time I
have to move next 2 times then back 2 times (or vice versa) to see the
updates/inserts. Here is the code (note that in my original post I
didn't have the actual form names in front of me. Form names are NOT
the problem)....

'**********************************************************
From the main form:
'**********************************************************
Private Sub loadSetStatusForm()

DoCmd.OpenForm "frmEditDODetail", acNormal, , , , acDialog

End Sub

'+++++++++++++++++++++++++++++++++++
' In the edit form.
'+++++++++++++++++++++++++++++++++++

Private Sub cmdInsert_Click()

Dim lngStatusID As Long
Dim strNotes As String
Dim dteDate As Date

Dim objCon As ADODB.Connection
Dim objCmd As ADODB.Command
Dim objPrm As ADODB.Parameter

Set objCon = New ADODB.Connection
Set objCmd = New ADODB.Command
Set objPrm = New ADODB.Parameter

If IsNull(cboStatus.Value) Then

MsgBox "Please Select a Status Message", vbOKOnly, "Error"
Me.cboStatus.SetFocus
Else

lngStatusID = Me.cboStatus.Value
dteDate = CDate(Format(Now(), "dd mmm yyyy"))

If Not IsNull(txtNotes.Value) Then
strNotes = Me.txtNotes.Value
Else
strNotes = ""
End If

objCon.Open (CurrentProject.Connection)

'Setup Command Object for DB Call
With objCmd
.CommandText = "sp_insert_do_status"
.CommandType = adCmdStoredProc
.ActiveConnection = objCon

Set objPrm = .CreateParameter("do_id", adInteger,
adParamInput, , g_lngDOID)
.Parameters.Append objPrm

Set objPrm = .CreateParameter("s_id", adInteger,
adParamInput, , lngStatusID)
.Parameters.Append objPrm

Set objPrm = .CreateParameter("dte", adDate,
adParamInput, , dteDate)
.Parameters.Append objPrm

Set objPrm = .CreateParameter("StatusNotes", adVarChar,
adParamInput, 255, strNotes)
.Parameters.Append objPrm

.Execute 'works fine. I see the changes in the table after
the insert

End With

objCon.Close

Set objCon = Nothing
Set objCmd = Nothing
Set objPrm = Nothing

Forms!frmDOMain!sfrmDOStatus.Form.Requery ' This doesn't work

DoCmd.Close acForm, "frmEditDODetail"

End If

End Sub

Unless someone tells me other wise, although this is a logical flow of
events (open main form - find record, flow to a form to edit the
record, return to main form & changes should be visible) it appears
that either way off base on how to make the changes visible or that MS
Access "doesn't work that way".

I have spent hours on this ridiculous problem.


rm said:
I have a main form (frmDO) with a subForm (frmDODetail) where the sub
control name is sfrmDODetail. The subform is a datasheet.
When I double click on sfrmDODetail and edit form is displayed
(frmEditDODetail).
When I save the changes in the edit form (frmEditDODetail) I want the
sub form (sfrmDODetail - frmDODetail) to display the edits/changes/
additions made by the user.
I have tried numerous different ways (many suggested in this group) to
make the sub form (sfrmDODetail - frmDODetail) requery. I have tried
Forms! etc, Dim frm as FORM_frmDODetail. I have spent 4 - 5 hours
trying every different combination. At one point I had a variation of
Forms! working. Then out of the blue the method no longer worked.
I am in the military - in Iraq. Three days ago I was laying in a 1
foot deep ditch with mortar rounds landing within a quarter mile of my
position. I am far more upset, frustrated about working with this
Microsoft Product!

I guess difficult/frustration are relative to how familiar
we are with a situation.  Most people would not think that
laying in a ditch was a preferred response  ;-)

I think your issue is that the Requery must wait until the
edits in frmEditDODetail have been completed.  This can be
done from frmEditDODetail's Close event ptocedure using:
        Forms!frmDO.sfrmDODetail.Form.Requery

A differnt approach is structurally cleaner because users
can not jump around your other forms (creating a confusing
scenario) and because frmEditDODetail has no need to "know"
which form opened it.  This is accomplished by opening
frmEditDODetail in Dialog mode immediately followed by the
requery:
        DoCmd.OpenForm "frmEditDODetail", WindowMode:=acDialog
        Me.Requery

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -
 
rm said:
Thank you for the response. Now the situation is degrading. I am
seeing very odd behaivor. Before I move to the "edit" form, save the
changes, return to the main form, move next then move prev (or move
prev then move next) and see the changes.  Now from time to time I
have to move next 2 times then back 2 times (or vice versa) to see the
updates/inserts. Here is the code (note that in my original post I
didn't have the actual form names in front of me. Form names are NOT
the problem)....
'**********************************************************
From the main form:
'**********************************************************
Private Sub loadSetStatusForm()
   DoCmd.OpenForm "frmEditDODetail", acNormal, , , , acDialog
'+++++++++++++++++++++++++++++++++++
' In the edit form.
'+++++++++++++++++++++++++++++++++++
Private Sub cmdInsert_Click()
   Dim lngStatusID As Long
   Dim strNotes As String
   Dim dteDate As Date
   Dim objCon As ADODB.Connection
   Dim objCmd As ADODB.Command
   Dim objPrm As ADODB.Parameter
   Set objCon = New ADODB.Connection
   Set objCmd = New ADODB.Command
   Set objPrm = New ADODB.Parameter
   If IsNull(cboStatus.Value) Then
       MsgBox "Please Select a Status Message", vbOKOnly, "Error"
       Me.cboStatus.SetFocus
   Else
       lngStatusID = Me.cboStatus.Value
       dteDate = CDate(Format(Now(), "dd mmm yyyy"))
       If Not IsNull(txtNotes.Value) Then
           strNotes = Me.txtNotes.Value
       Else
           strNotes = ""
       End If
       objCon.Open (CurrentProject.Connection)
       'Setup Command Object for DB Call
       With objCmd
           .CommandText = "sp_insert_do_status"
           .CommandType = adCmdStoredProc
           .ActiveConnection = objCon
           Set objPrm = .CreateParameter("do_id", adInteger,
adParamInput, , g_lngDOID)
           .Parameters.Append objPrm
           Set objPrm = .CreateParameter("s_id", adInteger,
adParamInput, , lngStatusID)
           .Parameters.Append objPrm
           Set objPrm = .CreateParameter("dte", adDate,
adParamInput, , dteDate)
           .Parameters.Append objPrm
           Set objPrm = .CreateParameter("StatusNotes", adVarChar,
adParamInput, 255, strNotes)
           .Parameters.Append objPrm
           .Execute 'works fine. I see the changes in the table after
the insert
       End With
       objCon.Close
       Set objCon = Nothing
       Set objCmd = Nothing
       Set objPrm = Nothing
       Forms!frmDOMain!sfrmDOStatus.Form.Requery ' This doesn't work
       DoCmd.Close acForm, "frmEditDODetail"
   End If
Unless someone tells me other wise, although this is a logical flow of
events (open main form - find record, flow to a form to edit the
record, return to main form & changes should be visible) it appears
that either way off base on how to make the changes visible or that MS
Access "doesn't work that way".

Even though I don't do ADO and I have no idea why you need
all that code, it looks like good code to me.  Assuming
there isn't some ADO thing getting in the way, I can only
think of two issues that might be going on here.  The easy
one is if sfrmDOStatus is not the name of the subform
**control** on the main form.  You probably already know
this, but, for completeness, the name of the form object
displayed by the subform control is irrelevant.

The other potential issue is that Access is too busy to
(re)load and redraw the subform after the requery.  This can
happen if the subform has a *lot* of records or for a
plethora of other unrelated reasons.  An easy way to tell if
the subform has been redrawn is when it makes the first
record the current record (if you need to make the same
record current, it would take a couple more lines of code
after the requery).  You can force the subform records to be
(re)loaded by adding another line after the requery:

Forms!frmDOMain!sfrmDOStatus.Form.RecordsetClone.MoveLast

If that doesn't take care of it, try adding a
Forms!frmDOMain!sfrmDOStatus.Form.Repaint
and/or one or two
DoEvents

Another stray thought is that if you will never be adding a
new record in frmEditDODetail, then you could get away with
using Refresh instead of Requery.

I do recommend that you move the Requery, etc. code into the
procedure that opens frmEditDODetail

Speaking of opening frmEditDODetail, how does it figure out
which record you want to edit?

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -
It is a bit embarrassing... I read a pretty good quote once that I can
only paraphrase "Global variables are bad. Only use them just as often
as you stop breathing... but remember that sometimes you do have to
hold your breath." I set a global variable.

Oh.. and it still doesn't work. I even miss "spoke". Sometime I now
have to go next, go prev 2X for the record to display.

Thank you for your assistance!
 
Back
Top