G
GLT
Hi,
I have a table which has three fields Type, Server and Service (table and
sample data below):
Type Server Service
DEV TEST12 Performance
PROD ALL Stats
DEV ALL Dummy Data
On my form, I use an option group to select the (a) individual server or (b)
ALL servers (See Server field above). I use the following code to add
records to the table when an 'ADD' button is clicked, which works fine:
Dim strSQL As String
strSQL = "INSERT INTO tblPermSrvcsIgnore " & _
"( Type, Server, [Service Name] )" & _
" SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type" & _
", IIf([FORMS]![frmAddPermNoMon]![Frame7]=2, 'ALL', " & _
"[FORMS]![frmAddPermNoMon]![fldSelServer]) AS Server" & _
", [FORMS]![frmAddPermNoMon]![fldSelSevice] AS [Service Name];"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Me![tblPermSrvcsIgnore SubForm].Requery
' Set the selected Service to 0 for ALL Servers
DoCmd.RunSQL "UPDATE Services SET Services.Valid = 0 WHERE
(((Services.Service) Like [FORMS]![frmAddPermNoMon]![fldSelSevice]));"
ElseIf Me![Frame7] = 1 Then
' Set the selected Service to 0 for Selected Server only
DoCmd.RunSQL "UPDATE Services SET Services.Valid = 0 WHERE
(((Services.Server) Like [FORMS]![frmAddPermNoMon]![fldSelServer]) AND
((Services.Service) Like [FORMS]![frmAddPermNoMon]![fldSelSevice]));"
End If
DoCmd.SetWarnings True
Me![tblPermSrvcsIgnore SubForm].Requery
The above works great except I can press the 'ADD' button and add as many
duplicates of the same records as I please, so in order to keep this table
slim and relevant, I want to place the following checks in place:
1) If I try to add the same record twice, then reject it
2) If a record where 'Server' = ALL, and Service = TESTDATA, and I try to
add another record for an individual server (e.g. TEST12) which also has a
Service = TESTDATA, then reject it (i.e. while a record exists for ALL
servers with a service name, do not allow records individual servers to be
added with the same service name)
3) If there are individual Servers with the Service = TESTDATA that exist in
the table, and a new record where Server=ALL is added (with the Service =
TESTDATA), then remove all the individual records with that service name
first, before adding the new Server=ALL record.
In essence what I am trying to achieve is to prevent duplicates, but also if
there is an entry where Server=ALL, then that entry overrides and prevents
individual entries where the Service field has the same value.
Any assistance would be greatly appreciated...
Cheers,
GLT.
I have a table which has three fields Type, Server and Service (table and
sample data below):
Type Server Service
DEV TEST12 Performance
PROD ALL Stats
DEV ALL Dummy Data
On my form, I use an option group to select the (a) individual server or (b)
ALL servers (See Server field above). I use the following code to add
records to the table when an 'ADD' button is clicked, which works fine:
Dim strSQL As String
strSQL = "INSERT INTO tblPermSrvcsIgnore " & _
"( Type, Server, [Service Name] )" & _
" SELECT [FORMS]![frmAddPermNoMon]![fldSelShutType] AS Type" & _
", IIf([FORMS]![frmAddPermNoMon]![Frame7]=2, 'ALL', " & _
"[FORMS]![frmAddPermNoMon]![fldSelServer]) AS Server" & _
", [FORMS]![frmAddPermNoMon]![fldSelSevice] AS [Service Name];"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Me![tblPermSrvcsIgnore SubForm].Requery
' Set the selected Service to 0 for ALL Servers
DoCmd.RunSQL "UPDATE Services SET Services.Valid = 0 WHERE
(((Services.Service) Like [FORMS]![frmAddPermNoMon]![fldSelSevice]));"
ElseIf Me![Frame7] = 1 Then
' Set the selected Service to 0 for Selected Server only
DoCmd.RunSQL "UPDATE Services SET Services.Valid = 0 WHERE
(((Services.Server) Like [FORMS]![frmAddPermNoMon]![fldSelServer]) AND
((Services.Service) Like [FORMS]![frmAddPermNoMon]![fldSelSevice]));"
End If
DoCmd.SetWarnings True
Me![tblPermSrvcsIgnore SubForm].Requery
The above works great except I can press the 'ADD' button and add as many
duplicates of the same records as I please, so in order to keep this table
slim and relevant, I want to place the following checks in place:
1) If I try to add the same record twice, then reject it
2) If a record where 'Server' = ALL, and Service = TESTDATA, and I try to
add another record for an individual server (e.g. TEST12) which also has a
Service = TESTDATA, then reject it (i.e. while a record exists for ALL
servers with a service name, do not allow records individual servers to be
added with the same service name)
3) If there are individual Servers with the Service = TESTDATA that exist in
the table, and a new record where Server=ALL is added (with the Service =
TESTDATA), then remove all the individual records with that service name
first, before adding the new Server=ALL record.
In essence what I am trying to achieve is to prevent duplicates, but also if
there is an entry where Server=ALL, then that entry overrides and prevents
individual entries where the Service field has the same value.
Any assistance would be greatly appreciated...
Cheers,
GLT.