In my form I am trying to add a new record, the code to add a record works correctly. I am trying to add a check which displays a message box, if the user atempts to add a record which already exists.
I have attempted to do this using the code below, the code I have added (which does not work properly) is within the While loop, the error I recieve is "Invalid or Unqualified reference" in the 6th line of code at the if statement section, where the "[PROJECT_NAME]" is not recognised
I have attempted to do this using the code below, the code I have added (which does not work properly) is within the While loop, the error I recieve is "Invalid or Unqualified reference" in the 6th line of code at the if statement section, where the "[PROJECT_NAME]" is not recognised
Code:
Set rst = dbs.OpenRecordset("tblPROJECTS")
NumRecords = DCount("*", "tblPROJECTS")
rst.MoveFirst
While Not rst.EOF
If ![PROJECT_NAME] = Me![Project_Name_Text] Then
MsgBox "A project with this name already exists, please enter a unique name"
rst.MoveNext
Wend
With rst
.AddNew
![PROJECT_THEME_ID] = Me![Project_Theme_Choice]
![PROJECT_ID] = Nz(DMax("[PROJECT_ID]", "tblPROJECTS"), 0) + 1
![PROJECT_NAME] = Me![Project_Name_Text]
![PROJECT_DESCRIPTION] = Me![Project_Description_Text]
![PROJECT_START_DATE] = Me![Project_Start_Date_Value]
![PROJECT_END_DATE] = Me![Project_End_Date_Value]
![PROJECT_LEADER_ID] = Me![Project_Lead_Choice]
.Update
.Close
End With
MsgBox "* New project added to list. *"