Manually toggling the accept responses switch on a Google Form at midnight is a terrible way to manage a deadline.

You either stay up late, forget entirely, or cut someone off five minutes early because you checked the clock wrong.

Fortunately, Google Forms has a hidden automation layer that handles this exact problem.

With a few lines of Apps Script, you can set a strict, precise cutoff time that runs entirely on Google's servers while you sleep.

Here is exactly how to build, test, and deploy that automation.

Why should you automate closing your Google Form?

Relying on human memory to close a form creates a window for late entries, which forces you to manually delete rows or have awkward conversations about why a late submission cannot be accepted. Automating the cutoff removes the human error and enforces a strict boundary.

  • Timed quiz windows: If you administer a test that must be completed between 9:00 AM and 10:00 AM, a manual cutoff is risky. A script ensures the form locks at exactly 10:00 AM, preventing students from gaining extra time and compromising the integrity of the assessment.
  • Grant and job applications: High-stakes submissions require absolute fairness. If an application deadline is explicitly stated as 11:59 PM Friday, accepting an entry at 12:03 AM Saturday creates an unfair advantage. Automation ensures the rule applies equally to everyone.
  • Event registrations: Venues and caterers require final headcounts at specific times. If your form stays open past the catering deadline, you risk taking payments or confirming seats for guests you can no longer actually accommodate.
  • Promotional giveaways: Contests are heavily regulated, and running a sweepstakes often requires a published, legally binding end time. An automated trigger ensures you comply with your own terms and conditions without needing to monitor the form on a weekend.
  • Time-bound feedback: When collecting employee sentiment or voting on a company initiative, an open-ended form invites stragglers who might skew a decision after the results have already been tabulated. Closing it automatically forces participants to act within the requested window.

What prerequisites do you need before writing the script?

Apps Script is powerful, but it requires specific permissions and settings to interact with your form. If these are not aligned before you write the code, your trigger will fail silently when the deadline arrives.

  • Editor access to the form: You cannot run an Apps Script on a form if you only have view or comment access. You must be an explicit Editor or the Owner of the file.
  • Correct Google account login: If you use multiple Google accounts in the same browser, Apps Script frequently authenticates against the default account rather than the one you are actively viewing the form with. Always open an incognito window or a dedicated browser profile to write and authorize your script.
  • Timezone alignment: The most common reason a deadline script fails is mismatched timezones. Your computer, your Google Calendar, and your Apps Script project can all technically exist in different timezones. You must verify the script editor timezone matches your intended deadline.
  • Understanding of Form IDs: Apps Script needs to know exactly which form to close. You will need the form's unique ID, which is the long string of random letters and numbers found in the URL between /d/ and /edit.
  • Authorization readiness: The first time you run an Apps Script, Google will present a security warning stating the app is unverified. You must be prepared to click through the Advanced settings to allow the script to execute on your account.

How to write the Apps Script to stop accepting responses

You can attach a script directly to a form, but using a standalone script with the FormApp.openById() method is often safer. It prevents accidental deletion if someone copies the form, and it allows you to manage multiple form deadlines from a single master script file.

To open the environment, navigate to script.google.com and click New project.

Delete the placeholder code in the editor and replace it with the following JavaScript:

/**
 * Closes a specific Google Form by disabling new responses.
 * Replace the string in openById with your actual Form ID.
 */
function closeMyForm() {
  // 1. Define the unique ID of the Google Form
  // You can find this in the URL of your form: 
  // docs.google.com/forms/d/YOUR_FORM_ID_HERE/edit
  const formId = '1A2b3C4d5E6f7G8h9I0jKlMnOpQrStUvWxYz';
  
  // 2. Open the form using the ID
  const form = FormApp.openById(formId);
  
  // 3. Set the form to stop accepting responses
  form.setAcceptingResponses(false);
  
  // 4. Log a confirmation message for debugging purposes
  Logger.log('Form closed successfully: ' + form.getTitle());
}

Once pasted, replace the placeholder formId string with your actual ID. Leave the single quotes around the ID intact.

Click the Save icon (the floppy disk) in the top toolbar.

Before setting up the automated schedule, you must test the code and authorize it. Select closeMyForm from the function dropdown in the toolbar and click the Run button.

Google will prompt you to review permissions. Choose your account, click Advanced, and click Go to Untitled project (unsafe). Click Allow. If you check your actual Google Form now, the toggle in the Responses tab will be switched to the off position.

Turn it back on manually so the form is open, ready for the trigger to do its job.

How to configure the time-driven trigger for your deadline

Writing the code is only half the process. You now need to tell Google's servers exactly when to execute that function. Apps Script uses "Triggers" to schedule code execution independently of your browser.

  1. In the Apps Script editor, look at the left-hand sidebar. Click the Triggers icon, which looks like a small alarm clock.
  2. In the bottom right corner of the screen, click the large blue button labeled + Add Trigger.
  3. A configuration modal will appear. Under Choose which function to run, select closeMyForm.
  4. Under Choose which deployment should run, leave it set to Head.
  5. Under Select event source, click the dropdown and change it from From form to Time-driven.
  6. Under Select type of time based trigger, choose Specific date and time. This is critical. Do not choose Hour timer or Day timer, as those run on recurring intervals.
  7. A new text input box will appear. Enter your exact deadline using the format YYYY-MM-DD HH:MM. For example, to close the form on October 31st, 2024 at 5:00 PM, type 2024-10-31 17:00.
  8. Under Failure notification settings, select Notify me immediately. This ensures you get an email if the script crashes.
  9. Click Save.

You will now see your trigger listed in the dashboard. Google will handle the rest, pinging the script at the exact minute you specified.

How to customize the closed form message for late submitters

When a form closes, Google displays a default, generic message: "The form is no longer accepting responses." This is a frustrating dead-end for users. It provides no context on why it closed, who to contact, or what alternative steps they can take.

You can modify your script to inject a custom, helpful message at the exact moment the form locks. This requires adding the setCustomClosedFormMessage() method to your function.

If you are using a quiz to Google Form workflow for students, telling them exactly what happens next lowers their anxiety and reduces the emails in your inbox.

Update your Apps Script to look like this:

function closeMyFormWithCustomMessage() {
  const formId = '1A2b3C4d5E6f7G8h9I0jKlMnOpQrStUvWxYz';
  const form = FormApp.openById(formId);
  
  // Define a helpful message explaining the closure
  const closedMessage = 'The Fall Assessment window closed at 5:00 PM EST. If you experienced technical difficulties, please email the instructor at [email protected] with your student ID.';
  
  // Apply the custom message
  form.setCustomClosedFormMessage(closedMessage);
  
  // Stop accepting responses
  form.setAcceptingResponses(false);
  
  Logger.log('Form closed with custom message.');
}

The wording of your closed message matters. A weak message simply restates that the form is closed. A strong message provides context, a timestamp, and a next action.

Event registration message

  • ❌ Weak: Registration is closed.
  • ✅ Strong: Registration for the Annual Summit closed on Friday, October 15th. We cannot accept walk-ins due to venue limits. To join the waitlist for next year, please visit our main website.

Application deadline message

  • ❌ Weak: We are no longer accepting applications.
  • ✅ Strong: The Q3 Grant Application period ended at 11:59 PM. Late submissions are not accepted under any circumstances. The Q4 application window will open on January 1st.

Troubleshooting common Apps Script trigger errors

Triggers run silently in the background. When they fail, they fail invisibly unless you configured failure notifications. If your form did not close when expected, or if you received an error email from Apps Script, check the execution logs.

Here is how to diagnose and resolve the most frequent errors that occur with time-driven form scripts.

Error Message Common Cause Step-by-Step Resolution
Exception: No item with the given ID could be found The Form ID in your script is incorrect, or the account running the script lacks permission to view the form. Verify the string in FormApp.openById(). Ensure you are logged into the exact Google account that owns the form, not a personal secondary account.
Authorization is required to perform that action The script was updated with new methods but the permissions were not re-approved, or the trigger was created by a different user. Open the script editor, select your function manually from the top bar, and click Run. Follow the popup prompts to grant the necessary OAuth permissions.
Exception: The script completed but the returned value is not a supported return type You used a reserved keyword or tried to return a complex object incorrectly at the end of the function. Remove any return statements at the end of your closeMyForm function. The script only needs to execute the closure, not return data to the trigger.
Form stayed open, no error in logs You created the script but forgot to actually build the time-driven trigger in the dashboard. Go to the Triggers menu (alarm clock icon). Ensure a trigger is listed, active, and set to Specific date and time with a future timestamp.
ReferenceError: FormApp is not defined You are likely trying to run this code outside of the Google Apps Script environment (e.g., in a local Node.js file). FormApp is a proprietary Google class. You must paste and run this code strictly within script.google.com or an Apps Script container.
Form closed an hour early or late The timezone of your Apps Script project does not match your local timezone, causing the trigger to fire at the wrong moment. Go to Project Settings (gear icon) in the editor. Check Show "appsscript.json" manifest file. Open that file and correct the timeZone string to match your locale.

What are the platform limits and timezone considerations?

Google Apps Script is a free tool, but it operates under strict quotas to prevent abuse. While closing a single form will not brush up against most limits, managing dozens of forms or running complex workflows requires understanding the platform's boundaries.

Google limits time-driven triggers. A standard consumer Google account can run triggers a maximum of 90 minutes per day in total execution time. Workspace (enterprise or education) accounts get 6 hours per day. Because closing a form takes roughly 0.2 seconds, execution time is rarely an issue for this specific task.

However, you are limited to 20 triggers per script project. If you are managing a massive university deployment and need to close 50 different quizzes at 50 different times, you cannot stack 50 triggers in one file. You must consolidate them or split them across multiple projects.

Timezone drift is the most dangerous variable in time-driven triggers.

Expert tip: Apps Script projects default to the timezone of the user who created them, at the moment they were created. If you travel across the country, create a script in Pacific Time, and later set a trigger thinking you are in Eastern Time, your form will close three hours late.

To guarantee absolute precision, always hardcode your timezone into your mental math or force the script manifest to match your current location. In the Apps Script editor, click the Project Settings gear icon. Check the box for Show "appsscript.json" manifest file in editor. Return to the code editor, open the appsscript.json file, and look for the timeZone key. Ensure it reads correctly, such as "America/New_York" or "Europe/London".

If you frequently build forms from external briefs or documents, keeping your environment standardized is crucial. Using tools to generate a Google Form from a description or template speeds up creation, but you must still verify the timezone of the resulting file before attaching a deadline script.

Finally, be aware of Google's trigger precision. When you set a recurring trigger (like "every hour"), Apps Script guarantees it will run sometime within a 15-minute window of that hour, not on the exact second. However, the Specific date and time trigger we configured earlier is much more precise, typically firing within 60 seconds of the requested minute. If a 60-second delay is unacceptable for your use case, Apps Script may not be the right tool for your deadline.

FAQ

Can I close a Google Form at a specific minute using Apps Script?

Yes. By using the "Specific date and time" trigger in the Apps Script dashboard, you can format your deadline down to the exact minute, such as 2024-11-05 14:30. The script will typically execute within 60 seconds of that target time.

What happens to a user who is actively typing when the form closes?

The form does not forcefully refresh or lock their browser tab while they are typing. However, when the user finally clicks the submit button, Google's servers will reject the payload. The user will see an error message stating the form is no longer accepting responses, and their typed data will be lost.

Do I need to keep my computer or browser open for the trigger to run?

No. Once the time-driven trigger is saved in the Apps Script dashboard, the instruction is handed off to Google's backend servers. You can close your browser, turn off your computer, or disconnect from the internet entirely, and the form will still close at the scheduled time.

How do I automatically reopen the form at a later date?

You can create a second function in the same script file that uses form.setAcceptingResponses(true). Once that function is saved, you simply return to the Triggers menu and add a new "Specific date and time" trigger pointing to this reopening function, setting the timestamp for your desired future date.

Writing scripts to manage form states gives you complete control over your data collection windows without requiring manual intervention. If you are regularly building complex forms, quizzes, or assessments that require strict deadlines, generating the initial form structure automatically can save just as much time as automating the closure. Tools like Doc2Form can convert your existing PDFs or instruction documents directly into a formatted Google Form in your Drive, leaving you free to simply paste in your Apps Script, set your trigger, and walk away.