Share via

Error 3075 Syntax error(missing operator) for Dcount

Anonymous
2015-10-10T10:00:49+00:00

Hi guys,

I need some help here. In addition to my earlier thread http://answers.microsoft.com/en-us/office/forum/office\_2013\_release-access/adding-a-limit-to-insertion-of-data/afdab8c1-bfdf-48b5-914b-56f25264d987

I have a registration Form with the fields StdID (for student ID) and CourseID.

I have a Registration Table with the fields Student ID(with a space inbetween) and CourseID.

I want to limit a unique StudentID from registering for more than 6 courses, so I enter the followin VBA code to my registration form.

Private Sub Form_BeforeInsert(Cancel As Integer)

    If (DCount("Student ID", "Registration", "Student ID=" & Me.StdID) = 6) Then

        MsgBox "You have reached the limit of courses allowed.", vbExclamation, "Can't Add Another Course"

        Cancel = True

    End If

End Sub

But I am getting the Error 3075 syntax error(missing operator).  May I know what is wrong here?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2015-10-10T13:52:00+00:00

    Thanks Ken!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-10-10T11:40:07+00:00

    As the column name includes spaces you need to wrap it in square brackets:

        If (DCount("[Student ID]", "Registration", "[Student ID]=" & Me.StdID) = 6) Then

    While Access allows spaces and other special characters to be used in object names, and Access templates etc often do so, it is nevertheless not best practice.  Instead use CamelCase or represent a space by an underscore character Like_This.

    As this question is a development of your other thread, it would have been more appropriate to post it there, or at least include a hyperlink to the other thread here.

    Was this answer helpful?

    0 comments No comments