Access: the code contains a syntax error

Anonymous
2019-09-24T20:04:37+00:00

When I try and place a command button on a form I get the following message:

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
{count} vote

18 answers

Sort by: Most helpful
  1. ScottGem 68,775 Reputation points Volunteer Moderator
    2019-09-25T01:57:01+00:00

    Ok, That is a constant and the full command should be:

    DoCmd.RunCommand acCmDRecordsGotoNew

    It would definitely be a syntax error if it stood alone. It could also be a syntax error if it is used where you can't add a new record.

    And yes, a compile error could interfere with a control wizard. Try commenting out the offending line (put an apostrophe in front of the line) and see if fixes the problem.

    0 comments No comments
  2. Anonymous
    2019-09-25T02:23:56+00:00

    I no longer can compile (grayed out). I tried deleting the form and redoing, and when i place the buttom, it gives me the same error. The button is intended to save the entered record, but i never get that far because of the pop up. 

    Why can't i compile now?

    0 comments No comments
  3. Anonymous
    2019-09-25T04:03:38+00:00

    Hmm, this is odd.  Have you tried running Repair?  Sounds like the wizard may have gotten corrupt.

    0 comments No comments
  4. ScottGem 68,775 Reputation points Volunteer Moderator
    2019-09-25T12:49:03+00:00

    The Compile option being grayed out means that the compile completed successfully and there are no more syntax errors. If you make a change in the code, the Compile option should return.

    But if the problem persists, then that's not the issue. So we need to move on. Does this happen on other databases? Can you create a new blank database and see if the problem persists? If it does, I would do a repair of Office.

    This is an unusual problem and may take some investigation to resolve.

    0 comments No comments
  5. Anonymous
    2019-09-25T14:14:06+00:00

    I have run compact and repair under "Info". I have also gone out to office/setup and reinstalled the apps. I do notice that Access is not included in Office 365 Home edition, but is available for the PC only. I believe that Office was installed on the computer when i purchased it and i just activated it. I have run regedit and cannot find where Office (Access) is registered. Is that a problem? Thanks for your help.

    0 comments No comments