Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:32:06+00:00 2026-06-09T08:32:06+00:00

Having trouble with my insert into sql. All the code below works, excep the

  • 0

Having trouble with my insert into sql. All the code below works, excep the SQL strings that add a value for level. Here is my onclick code for a form with three boxes. The table that stores the pH, Temp, and Level values has a number format with field size ‘single’ set for all three fields.

Again, if I leave the ‘level’ box blank, it works! But when I try to insert a level value, with any other combination of values, it fails.

Code Below:

Private Sub SubmitSampleData_Click()
Dim pH, Temp, Level As Single
Dim TodaysDate As Date

TodaysDate = Date

If IsNull(Me.pH.Value) Then
    pH = 1
Else
    pH = Me.pH.Value
End If
If IsNull(Me.Temp.Value) Then
    Temp = 1
Else
    Temp = Me.Temp.Value
End If
If IsNull(Me.Level.Value) Then
    Level = 1
Else
Level = Me.Level.Value
End If

If Level = 1 And Temp = 1 And pH = 1 Then
     Exit sub
ElseIf Level = 1 And Temp = 1 Then
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, pH) VALUES (#" & TodaysDate & "#, " & pH & ")"
ElseIf Temp = 1 And pH = 1 Then
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, Level) VALUES (#" & TodaysDate & "#, " & Level & ")"
ElseIf Level = 1 And pH = 1 Then
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, Temp) VALUES (#" & TodaysDate & "#, " & Temp & ")"
ElseIf Level = 1 Then
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, pH, Temp) VALUES (#" & TodaysDate & "#, " & pH & ", " & Temp & ")"
ElseIf Temp = 1 Then
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, pH, Level) VALUES (#" & TodaysDate & "#, " & pH & ", " & Level & ")"
ElseIf pH = 1 Then
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, Temp, Level) VALUES (#" & TodaysDate & "#, " & Temp & ", " & Level & ")"
Else    
    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, pH, Temp, Level) VALUES (#" & TodaysDate & "#, " & pH & ", " & Temp & ", " & Level & ")"
End If

MsgBox "Submit Successful!", vbOKOnly, "Success!"

Me.pH.Value = Null
Me.Temp.Value = Null
Me.Level.Value = Null
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:32:09+00:00Added an answer on June 9, 2026 at 8:32 am

    Level is a reserved word and must be enclosed in square brackets.

    CurrentDb.Execute "INSERT INTO SampleDataQuery (DateCreated, [Level]) VALUES (#" _
       & TodaysDate & "#, " & Level & ")"
    

    Reserved words

    Jet
    ACE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble inserting values into my Account table that's in a SQL
I am having trouble with insert the same value N time In SQL via
I'm having trouble with a method I wrote to insert string words into a
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
I am having some trouble inserting an array into the sql database. my error
I am having trouble with a sql query. I need to insert a row
I am having trouble finding the documentation to be able to add non-SQL variables
I'm having trouble inserting related rows into my database. When I insert new objects
Having trouble with each function... Will try to explain by example... In my code,
Having trouble with an .htaccess file on WAMP. Works on the live server, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.