Rx_
Nothing In Moderation
- Local time
- Today, 12:54
- Joined
- Oct 22, 2009
- Messages
- 2,795
Access 2007 - Linked Tables
This is part of a Add button that also calls the double_click to add an item in the listbox to another list box.
i.e. Private Sub lstWellsByArea_DblClick(Cancel As Integer)
Goal: prevent a duplicate record from being added- of the columns ID_NEPA, ID_Wells, and Activity (where Activity = "A")
considering: before line 60, create SQL statement, test for recordcount greater than zero, if true then set Cancel = True and exit sub
In effect ignoring the request to add a duplicate.
Or: add an index for uniqueness - and trap the error - exit the subroutine
The problem with this one is: When Activity = "A" On Add New Activity = "A" on Delete Activity = "I" so, in theory, there could be multiple "I" for the three fields.
Any suggestions?
What would be the best way?
Existing Code:
To add an unique index to three fields, the following instructions were found:
create multifield index to enforce unique combinations
1. Open the table in Design view
2. Click Indexes on the toolbar.
3. In the first blank row in the Index Name column, type a name for the index ). You can name the index after one of the index fields, or use another name.
4. In the Field Name column, click the arrow and select the first field for the index.
5. In the next row in the Field Name column, select the second field for the index. (Leave the Index Name column blank in that row.) Repeat this step until you have selected all the fields you want to include in this index.
This is part of a Add button that also calls the double_click to add an item in the listbox to another list box.
i.e. Private Sub lstWellsByArea_DblClick(Cancel As Integer)
Goal: prevent a duplicate record from being added- of the columns ID_NEPA, ID_Wells, and Activity (where Activity = "A")
considering: before line 60, create SQL statement, test for recordcount greater than zero, if true then set Cancel = True and exit sub
In effect ignoring the request to add a duplicate.
Or: add an index for uniqueness - and trap the error - exit the subroutine
The problem with this one is: When Activity = "A" On Add New Activity = "A" on Delete Activity = "I" so, in theory, there could be multiple "I" for the three fields.
Any suggestions?
Existing Code:
Code:
40 Set dbNEPA_Well = CurrentDb()
50 Set rstNEPA_WellTable = dbNEPA_Well.OpenRecordse (SQLNEPA_WellTable, dbOpenDynaset)
60 rstNEPA_WellTable.AddNew
70 rstNEPA_WellTable!ID_NEPA = Me.Recordset!ID_NEPA
80 rstNEPA_WellTable!ID_Wells = Me.lstWellsByArea.Column(0) 'ID_Wells
90 rstNEPA_WellTable!Activity = "A"
100 rstNEPA_WellTable!Created = Now()
110 rstNEPA_WellTable.Update
120 rstNEPA_WellTable.Close
130 Set rstNEPA_WellTable = Nothing
140 Set dbNEPA_Well = Nothing
To add an unique index to three fields, the following instructions were found:
create multifield index to enforce unique combinations
1. Open the table in Design view
2. Click Indexes on the toolbar.
3. In the first blank row in the Index Name column, type a name for the index ). You can name the index after one of the index fields, or use another name.
4. In the Field Name column, click the arrow and select the first field for the index.
5. In the next row in the Field Name column, select the second field for the index. (Leave the Index Name column blank in that row.) Repeat this step until you have selected all the fields you want to include in this index.
Last edited: