PC Review


Reply
Thread Tools Rate Thread

A2002: need help with form scenario

 
 
=?windows-1250?Q?Vladim=EDr_Cvajniga?=
Guest
Posts: n/a
 
      25th May 2007
For one of form's subforms I have a query with 3 tables:
SELECT Kniha.DATUZP, DPH.*, Val(Left([DPH].[TypDA],1))<5 AS Vstup, Abs(Not
(((Left([KNIHA].[TypDokl],1))="Z") And ((Left([DPH].[TYPDA],1)) Between "5"
And "8"))) AS bSoucet, [DPH].[ZAKLAD]*[bSoucet] AS sumZAKLAD,
[DPH].[DAN]*[bSoucet] AS sumDAN, [DPH].[SDANI]*[bSoucet] AS sumSDANI,
Year([DATUZP]) AS rokDoklad, Par3Uc02.RokUc AS rokParam,
DateSerial(Year([Kniha].[DATUZP]),Month([Kniha].[DATUZP]),1) AS zacDoklad,
DateSerial([Par3Uc02].[RokUC],[Par3Uc02].[MesUc],1) AS zacParam,
([Vstup]=True) And (([rokDoklad]<>[rokParam]) Or ([zacDoklad]>[zacParam]))
AS b1, ([Vstup]=False) And ([zacDoklad]<>[zacParam]) AS b2
FROM Par3Uc02, DPH INNER JOIN Kniha ON DPH.ID_Kniha = Kniha.ID_Kniha
ORDER BY DPH.SAZBA;

Kniha: lookup table
Par3Uc02: parameter table (1 record)
DPH: main subform's data table

Calculated fields sumZaklad, sumDAN, sumZaklad are summed in form's header
text-boxes:
Text32: =Sum([sumZAKLAD])
Text33: =Sum([sumDAN])
txtSumSdani: =Sum([sumSDANI])

Calculated fields b1 and b2 affect conditional formatting of some
text-boxes. The formatting is based on an expression:
[b1] Or [b2]

I need b1 and b2 for validation rules as well.

Subform's RecordsetType is set to 1, ie. Dynaset (Inconsistent Updates).
————————————————————————————————————
What I need:
1) have the sums in subform's header
2) when record(s) is (are) deleted: delete only record(s) in main data table
(DPH) and leave lookup table (Kniha) and parameter table (Par3Uc02)
untouched
3) avoid DLookups in query because they significantly slow down perfomance:
on my slow machine it takes <2.5 seconds to open (very complex) form
without DLookups, >5 seconds with DLookups; this is a "DLookups" query:
SELECT DLookUp("DATUZP","Kniha","ID_Kniha=" & CStr([DPH].[ID_Kniha])) AS
DATUZP, Left(DLookUp("TypDokl","Kniha","ID_Kniha=" &
CStr([DPH].[ID_Kniha])),1) AS TypDokl1, DPH.*, Val(Left([DPH].[TypDA],1))<5
AS Vstup, Abs(Not ((([TypDokl1])="Z") And ((Left([DPH].[TYPDA],1)) Between
"5" And "8"))) AS bSoucet, [DPH].[ZAKLAD]*[bSoucet] AS sumZAKLAD,
[DPH].[DAN]*[bSoucet] AS sumDAN, [DPH].[SDANI]*[bSoucet] AS sumSDANI,
Year([DATUZP]) AS rokDoklad, DLookUp("RokUc","Par3Uc02") AS rokParam,
DLookUp("MesUc","Par3Uc02") AS mesParam,
DateSerial(Year([DATUZP]),Month([DATUZP]),1) AS zacDoklad,
DateSerial([rokParam],[mesParam],1) AS zacParam, ([Vstup]=True) And
(([rokDoklad]<>[rokParam]) Or ([zacDoklad]>[zacParam])) AS b1,
([Vstup]=False) And ([zacDoklad]<>[zacParam]) AS b2
FROM DPH
ORDER BY DPH.SAZBA;
————————————————————————————————————
The problems I have:
1) without DLookups: DELETE deletes records in all three tables
2) with DLookups:
a) slow performance
b) can't find a way to delete records only from DPH and leave Kniha &
Par3Uc02 untouched (see "My scenario" below); I have a function selSQL (see
below) to create a filter for DELETE query (only from selected record(s)),
ie. "DELETE * from DPH WHERE " & strFilter, but I'm not sure which Before*
and After* event procedures should I use and how
3) there might be a problem with Par3Uc02 with only one record;
when I test deletion: first deletion seems to perform OK, next
deletion(s) give(s) me an error message while creating filter - debug stops
at .MoveFirst in selSQL (variable not set)

Public Function selSQL(frm As Variant, fldName As String, Optional apostrof
As Boolean) As String
Dim a As String, sq As String, rs As DAO.Recordset, i As Integer

a = IIf(apostrof, "'", "")

'jestliže je oznaèené pouze nová vìta, tak EXIT
If (frm.SelHeight < 2 And frm.NewRecord) Then Exit Function

If frm.SelHeight = 0 Then
selSQL = "(" & fldName & "=" & a & CStr(frm.Controls(fldName).Value) &
a & ")"
Exit Function
End If

sq = ""
Set rs = frm.RecordsetClone
With rs
.MoveFirst
.Move frm.SelTop - 1
For i = 1 To frm.SelHeight
If Not .EOF Then
sq = sq & a & CStr(rs(fldName).Value) & a & ","
.MoveNext
End If
Next i
.Close
End With
Set rs = Nothing

sq = Left(sq, Len(sq) - 1)
sq = fldName & " in (" & sq & ")"
selSQL = sq

End Function
————————————————————————————————————
My scenario:
1) create filter sqDelete:
Private Sub Form_Delete(Cancel As Integer)
sqDelete = selSQL(Me, "ID_DPH")
End Sub
----------------
2a)
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContinue
Cancel = True
If MsgBox("Do you want to delete record(s)?", vbYesNo + vbQuestion) =
vbYes Then
'create DELETE query with sqDelete as filter
'DoCmd.RunSQL strDeleteQuery
End If
End Sub

or

2b)
Private Sub Form_AfterDelConfirm(Status As Integer)
If Status = acDeleteOK Then
'create DELETE query with sqDelete as filter
'DoCmd.RunSQL strDeleteQuery
Else
Status = acDeleteCancel
End If
End Sub

I think that 1) & 2b) should do what I want but I'm quite unsure... :-/
————————————————————————————————————


TYVM in advance.

Vlado

P.S. Is there any way to create similar query, ie. with more than one table,
which (on deletion) doesn't delete record(s) in all tables?

 
Reply With Quote
 
 
 
 
=?windows-1250?Q?Vladim=EDr_Cvajniga?=
Guest
Posts: n/a
 
      25th May 2007
P.P.P.S.
The error I'm getting, when I try to delete record(s), is 3420 - Object
invalid or no longer set.

 
Reply With Quote
 
=?windows-1250?Q?Vladim=EDr_Cvajniga?=
Guest
Posts: n/a
 
      25th May 2007
Ooops,
with DLookups 2b) can't find a way to delete records only from DPH

belongs to
1) without DLookups

V.

"Vladimír Cvajniga" <(E-Mail Removed)> píše v diskusním pøíspìvku
news:(E-Mail Removed)...
> For one of form's subforms I have a query with 3 tables:
> SELECT Kniha.DATUZP, DPH.*, Val(Left([DPH].[TypDA],1))<5 AS Vstup, Abs(Not
> (((Left([KNIHA].[TypDokl],1))="Z") And ((Left([DPH].[TYPDA],1)) Between
> "5" And "8"))) AS bSoucet, [DPH].[ZAKLAD]*[bSoucet] AS sumZAKLAD,
> [DPH].[DAN]*[bSoucet] AS sumDAN, [DPH].[SDANI]*[bSoucet] AS sumSDANI,
> Year([DATUZP]) AS rokDoklad, Par3Uc02.RokUc AS rokParam,
> DateSerial(Year([Kniha].[DATUZP]),Month([Kniha].[DATUZP]),1) AS zacDoklad,
> DateSerial([Par3Uc02].[RokUC],[Par3Uc02].[MesUc],1) AS zacParam,
> ([Vstup]=True) And (([rokDoklad]<>[rokParam]) Or ([zacDoklad]>[zacParam]))
> AS b1, ([Vstup]=False) And ([zacDoklad]<>[zacParam]) AS b2
> FROM Par3Uc02, DPH INNER JOIN Kniha ON DPH.ID_Kniha = Kniha.ID_Kniha
> ORDER BY DPH.SAZBA;
>
> Kniha: lookup table
> Par3Uc02: parameter table (1 record)
> DPH: main subform's data table
>
> Calculated fields sumZaklad, sumDAN, sumZaklad are summed in form's header
> text-boxes:
> Text32: =Sum([sumZAKLAD])
> Text33: =Sum([sumDAN])
> txtSumSdani: =Sum([sumSDANI])
>
> Calculated fields b1 and b2 affect conditional formatting of some
> text-boxes. The formatting is based on an expression:
> [b1] Or [b2]
>
> I need b1 and b2 for validation rules as well.
>
> Subform's RecordsetType is set to 1, ie. Dynaset (Inconsistent Updates).
> ————————————————————————————————————
> What I need:
> 1) have the sums in subform's header
> 2) when record(s) is (are) deleted: delete only record(s) in main data
> table (DPH) and leave lookup table (Kniha) and parameter table (Par3Uc02)
> untouched
> 3) avoid DLookups in query because they significantly slow down
> perfomance:
> on my slow machine it takes <2.5 seconds to open (very complex) form
> without DLookups, >5 seconds with DLookups; this is a "DLookups" query:
> SELECT DLookUp("DATUZP","Kniha","ID_Kniha=" & CStr([DPH].[ID_Kniha])) AS
> DATUZP, Left(DLookUp("TypDokl","Kniha","ID_Kniha=" &
> CStr([DPH].[ID_Kniha])),1) AS TypDokl1, DPH.*,
> Val(Left([DPH].[TypDA],1))<5 AS Vstup, Abs(Not ((([TypDokl1])="Z") And
> ((Left([DPH].[TYPDA],1)) Between "5" And "8"))) AS bSoucet,
> [DPH].[ZAKLAD]*[bSoucet] AS sumZAKLAD, [DPH].[DAN]*[bSoucet] AS sumDAN,
> [DPH].[SDANI]*[bSoucet] AS sumSDANI, Year([DATUZP]) AS rokDoklad,
> DLookUp("RokUc","Par3Uc02") AS rokParam, DLookUp("MesUc","Par3Uc02") AS
> mesParam, DateSerial(Year([DATUZP]),Month([DATUZP]),1) AS zacDoklad,
> DateSerial([rokParam],[mesParam],1) AS zacParam, ([Vstup]=True) And
> (([rokDoklad]<>[rokParam]) Or ([zacDoklad]>[zacParam])) AS b1,
> ([Vstup]=False) And ([zacDoklad]<>[zacParam]) AS b2
> FROM DPH
> ORDER BY DPH.SAZBA;
> ————————————————————————————————————
> The problems I have:
> 1) without DLookups: DELETE deletes records in all three tables
> 2) with DLookups:
> a) slow performance
> b) can't find a way to delete records only from DPH and leave Kniha &
> Par3Uc02 untouched (see "My scenario" below); I have a function selSQL
> (see below) to create a filter for DELETE query (only from selected
> record(s)), ie. "DELETE * from DPH WHERE " & strFilter, but I'm not sure
> which Before* and After* event procedures should I use and how
> 3) there might be a problem with Par3Uc02 with only one record;
> when I test deletion: first deletion seems to perform OK, next
> deletion(s) give(s) me an error message while creating filter - debug
> stops at .MoveFirst in selSQL (variable not set)
>
> Public Function selSQL(frm As Variant, fldName As String, Optional
> apostrof As Boolean) As String
> Dim a As String, sq As String, rs As DAO.Recordset, i As Integer
>
> a = IIf(apostrof, "'", "")
>
> 'jestliže je oznaèené pouze nová vìta, tak EXIT
> If (frm.SelHeight < 2 And frm.NewRecord) Then Exit Function
>
> If frm.SelHeight = 0 Then
> selSQL = "(" & fldName & "=" & a & CStr(frm.Controls(fldName).Value)
> & a & ")"
> Exit Function
> End If
>
> sq = ""
> Set rs = frm.RecordsetClone
> With rs
> .MoveFirst
> .Move frm.SelTop - 1
> For i = 1 To frm.SelHeight
> If Not .EOF Then
> sq = sq & a & CStr(rs(fldName).Value) & a & ","
> .MoveNext
> End If
> Next i
> .Close
> End With
> Set rs = Nothing
>
> sq = Left(sq, Len(sq) - 1)
> sq = fldName & " in (" & sq & ")"
> selSQL = sq
>
> End Function
> ————————————————————————————————————
> My scenario:
> 1) create filter sqDelete:
> Private Sub Form_Delete(Cancel As Integer)
> sqDelete = selSQL(Me, "ID_DPH")
> End Sub
> ----------------
> 2a)
> Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
> Response = acDataErrContinue
> Cancel = True
> If MsgBox("Do you want to delete record(s)?", vbYesNo + vbQuestion) =
> vbYes Then
> 'create DELETE query with sqDelete as filter
> 'DoCmd.RunSQL strDeleteQuery
> End If
> End Sub
>
> or
>
> 2b)
> Private Sub Form_AfterDelConfirm(Status As Integer)
> If Status = acDeleteOK Then
> 'create DELETE query with sqDelete as filter
> 'DoCmd.RunSQL strDeleteQuery
> Else
> Status = acDeleteCancel
> End If
> End Sub
>
> I think that 1) & 2b) should do what I want but I'm quite unsure... :-/
> ————————————————————————————————————
>
>
> TYVM in advance.
>
> Vlado
>
> P.S. Is there any way to create similar query, ie. with more than one
> table, which (on deletion) doesn't delete record(s) in all tables?
>


 
Reply With Quote
 
=?windows-1250?Q?Vladim=EDr_Cvajniga?=
Guest
Posts: n/a
 
      25th May 2007
Sometimes, when I try to delete a record, I get a message: Record is
deleted.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A2002: Form_Timer pops up the form =?windows-1250?Q?Vladim=EDr_Cvajniga?= Microsoft Access Forms 4 12th Mar 2007 12:40 AM
A2002 (sub)form behaviour driving me crazy!!! =?windows-1250?Q?Vladim=EDr_Cvajniga?= Microsoft Access Forms 8 10th Mar 2007 02:05 AM
activate form on open A2002 Brigitte P Microsoft Access Forms 2 15th Jan 2005 07:41 AM
Bug: print preview in form datasheet with server filter on crashes access (ADP A2002 SP3) Malcolm Cook Microsoft Access Forms 4 24th Jun 2004 08:38 AM
Bug: print preview in form datasheet with server filter on crashes access (ADP A2002 SP3) Malcolm Cook Microsoft Access ADP SQL Server 0 22nd Apr 2004 11:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:30 PM.