Paul
I made the else look like the following and I still get two messages:
If TotalEst = 0 And TotalAct = 0 Then
DoCmd.SetWarnings False
MySql = "Delete from TabActuals " & MyWhere
DoCmd.RunSQL MySql
Else
MsgBox "Cannot delete record if there are hours in Actual or
Estimate", vbOKOnly, "Delete Error"
Cancel = True
End If
John
:
Ah...you haven't canceled the Delete...put the following in the Else
Cancel = True
And get rid of the Docmd.CancelEvent....that should only be used under
certain conditions in Macros.
--
Paul Overway
Logico Solutions
http://www.logico-solutions.com
Paul
Why would my error message appear twice? I tried removing a record
with
the
hours not equal to zero.
John
:
I suspect it actually is being executed, but the record hasn't
really
been
deleted yet. Try moving the requery to the AfterDelConfirm event.
--
Paul Overway
Logico Solutions
http://www.logico-solutions.com
Paul
Here is the code.
Private Sub Form_AfterInsert()
Dim MyDB As DAO.Database
Dim STRCRITERIA As String
Dim ActHrs As DAO.Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set ActHrs = MyDB.OpenRecordset("TabActuals", DB_OPEN_DYNASET)
With ActHrs
.AddNew
!UserName = Me.UserName
!ProjectName = Me.ProjectName
!ActYear = Me.EstYear
.Update
End With
Me.Parent.FrmHoursActuals.Requery <==== Working.
End Sub
Private Sub Form_Delete(Cancel As Integer)
Dim MyDB As DAO.Database
Dim MySet As DAO.Recordset
Dim TotalAct As Long
Dim TotalEst As Long
Dim MyName As String
Dim MyYear As Double
Dim MyWhere As String
Dim MyProject As String
Dim MySql As String
MyName = Me.UserName
MyYear = Me.EstYear
MyProject = Me.ProjectName
MyWhere = "Where [UserName] = " & Chr(34) & MyName & Chr(34)
MyWhere = MyWhere + " AND [ProjectName] = " & Chr(34) &
MyProject
&
Chr(34)
MyWhere = MyWhere + " AND [ActYEAR] = " & MyYear
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MySet = MyDB.OpenRecordset("Select TotAct from
QryTabActuals
" &
MyWhere, DB_OPEN_DYNASET)
With MySet
.MoveFirst
TotalAct = !TotAct
End With
MyWhere = "Where [UserName] = " & Chr(34) & MyName & Chr(34)
MyWhere = MyWhere + " AND [ProjectName] = " & Chr(34) &
MyProject
&
Chr(34)
MyWhere = MyWhere + " AND [EstYEAR] = " & MyYear
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MySet = MyDB.OpenRecordset("Select TotEst from
QryTabEstimate
"
&
MyWhere, DB_OPEN_DYNASET)
With MySet
.MoveFirst
TotalEst = !TotEst
End With
Set MyDB = Nothing
Set MySet = Nothing
If TotalEst = 0 And TotalAct = 0 Then
DoCmd.SetWarnings False
MySql = "Delete from TabActuals " & MyWhere
DoCmd.RunSQL MySql
Me.Parent.FrmHoursActuals.Requery <=== not working
Else
DoCmd.CancelEvent
MsgBox "Cannot delete record if there are hours in Actual
or
Estimate", vbOKOnly, "Delete Error"
End If
End Sub
:
Post your code.
--
Paul Overway
Logico Solutions
http://www.logico-solutions.com
Paul
This did work on the adding of the record, thanks. I had to
change
rows
for
the requery to work. I'm still have the problem with the
delete.
I
put
the
same code where I delete the record and the requery did not
work.
John
:
In the subform routine where you're adding the record, put
Me.Parent.NameOfOtherSubform.Requery
--
Paul Overway
Logico Solutions
http://www.logico-solutions.com
I have searched the discussion group and all the solutions
will
not
work.
I have a main form with 2 subforms. Both of the subforms
are
"Continuous
Forms". When a record is added to the 1st subform, I have
code
to
add
to
the
table behind the 2nd subform. I cannot get the 2nd subform
to
refresh
when
I
add the record.
Now I'm trying to delete the record and I tried using both
Refresh
and
Requery method in the after update and on delete event of
1st
subform.
All
that is showing up is "#delete" in all the fields. Any
suggestions
will
help.