Jun 16 2021 06:24 AM
Hello all,
I am new here and new to Access. I have created a database for my employer to track job records. Each job has a unique job number. I tried to use unique indexes to stop duplicate values for that field in the "JOB_TABLE", however those indexes are not supported once the tables have been linked to sharepoint. I can no longer edit tables since they have been linked to sharepoint as well. I would like to use the verification rule for the "JOB#" field on my "JOB_FORM" to check for equal values in the "JOB#" field of my "JOB_SHEET" form so that when you enter a job number on the "JOB_FORM" that already exists in the "JOB_SHEET" the verification message shows up "Cannot duplicate Job#". I have tried to do this using macros and expressions and keep getting errors or it only checks against the last number in the "JOB_SHEET, JOB#" form. I'm assuming now that it will have to be a VBA code that does the job. Is there anyone out there that can help with this? Any input would be greatly appreciated.
Thanks,
Kiefer
Jun 16 2021 08:14 AM - edited Jun 16 2021 08:16 AM
Hi,
Why do you want to check for the duplicate in another form instead of in the table?
If they write to the same table you can use VBA code like this in the Before Update event of a JobNo textbox:
If Not IsNull(Dlookup("JobNo", "JOB_TABLE", _
"JobNo = " & Me!JobNo)) _
And Me!JobNo <> nz(Me!JobNo.OldValue) Then
MsgBox Me!JobNo & " already exists.", vbOKOnly, "Duplicate!"
Cancel = True
End If
Servus
Karl
*********
http://AccessDevCon.com
https://www.donkarl.com
Jun 16 2021 09:12 AM
Karl,
Thank you very much for your input. I tried what you suggested. However, I keep getting an error where Access is telling me it cannot find the respective field "JOB". As the actual field name in the table is "JOB#", I am wondering if it does not recognize the "#" character. I could try changing the field name in the Sharepoint table to what you have in your code as "JobNo". However, I fear this may break other relationships within the database after update. Here is the code I entered in the BeforeUpdate area of the textbox control.
If Not IsNull(Dlookup("JOB#", "JOB_TABLE", _
"JOB# = " & Me!JOB#)) _
And Me!JOB# <> nz(Me!JOB#.OldValue) Then
MsgBox Me!JOB# & " already exists.", vbOKOnly, "Duplicate!"
Cancel = True
End If
Thoughts?
Jun 16 2021 09:19 AM - edited Jun 16 2021 09:20 AM
Hi,
Special characters like # in object or field names very often cause problems and should be avoided. If you are able to change that name then do it ASAP. Meanwhile you have to always enclose the name in square brackets:
If Not IsNull(Dlookup("[JOB#]", "JOB_TABLE", _
"[JOB#] = " & Me![JOB#])) _
And Me![JOB#] <> nz(Me![JOB#].OldValue) Then
MsgBox Me![JOB#] & " already exists.", vbOKOnly, "Duplicate!"
Cancel = True
End If
Servus
Karl
*********
http://AccessDevCon.com
https://www.donkarl.com
Jun 16 2021 05:45 PM - edited Jun 16 2021 05:46 PM
@kiefertrey Do you not have permissions to see the linked SharePoint lists which are tables in your Access FE?
It's a over an hour long, but Albert Kallal's recent presentation might be useful here. I believe it addresses the issue of modifying SP lists, but it's very useful anyway. Have a look when you have time.
Jun 17 2021 01:48 AM - edited Jun 17 2021 01:54 AM
Hi,
Just to add some details to George's comment on the Sharepoint design changes:
If you have the permissions to do changes on the Sharepoint list, you could set the field to accept only unique values. This is of course possible in the column settings in Sharepoint itself but as Albert showed in the mentioned video even in Access. You can open the linked Sharepoint list in datasheet view, choose the Fields tab in the ribbon and change the Unique setting for the column.
In case the Fields tab is greyed out for the Sharepoint list/table you first have to check the option to use the cache format that is compatible with Access 2010 and later in File - Option - Current Database - Caching Web Service and Sharepoint tables.
Servus
Karl
*********
http://AccessDevCon.com
https://www.donkarl.com
Jun 17 2021 04:32 AM
@Karl Donaubauer @George Hepworth Guys. This sounds great. I will definitely check it out. Thanks a bunch!