Copy the query from myinsert to the Access and try to run it from there. You often have a more explicit error message.
Main Topics
Browse All TopicsI am simply trying to insert data in an access database, into a form called YesPledgeForm. I have almost the exact same code on another page which works fine. It inserts the data into a form called NoPledgeForm and works perfect. So I know that it has nothing to do with the connection string. I CANNOT figure out what the difference is or why I am getting this error. I have been looking at it off and on for 2 days so I figured it was time to try something else. So here we are. My code is below and the error that I am getting follows the code. Thanks for any help. Oh, all the fields in the table are text except the amount field which is an integer.
Dim myconnect As OleDbConnection
Dim mycommand As OleDbCommand
Dim myinsert As String
***********error appears on line below*********************
myinsert = "INSERT INTO YesPledgeForm (Amount, MailCode, IDNum, Email, Phone, Yesbox, Occupation, Employer, BatchNum) VALUES (" & txtAmount.Text & ", '" & txtMailCode.Text & "', '" & txtID.Text & "', '" & txtEmail.Text & "', '" & txtPhone.Text & "', '" & txtYesBox.Text & "', '" & txtOccupation.Text & "', '" & txtEmployer.Text & "', '" & Session("BatchNum") & "')"
***********error appears on line above*********************
myconnect = New OleDbConnection(Session("c
myconnect.Open()
mycommand = New OleDbCommand(myinsert, myconnect)
mycommand.ExecuteNonQuery(
Exception Details: System.NullReferenceExcept
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
in access it said microsoft set 1 field(s) to Null due to a type conversion error, and it didnt add 0 records to the table due to key violations, 0 records due to lock violations and 0 records due to validation rule violations.
but here is the wierd thing since the first post i have added some code which includes another variable for the NOW function and another variable to do a check digit on. I am getting the same error as before only in a different place now. Here it is:
If Me.IsPostBack Then
Dim mydate As String
Session.Add(mydate, "")
Session("mydate") = Format(Now(), "yyyyMMdd")
Session("keyedtotal") = Session("keyedtotal") + txtAmount.Text
Dim myconnect As OleDbConnection
Dim mycommand As OleDbCommand
Dim myinsert As String
Dim idstring As String
*************error on line below now*****************
idstring = txtIDNum.Text
**************************
If CheckDigit(idstring, 3, 2) = True Then
myinsert = "INSERT INTO YesPledgeForm (Amount, MailCode, IDNum, Email, Phone, Yesbox, Occupation, Employer, BatchNum, ResponseDate, DateKeyed) VALUES (" & txtAmount.Text & ", '" & txtMailCode.Text & "', '" & txtID.Text & "', '" & txtEmail.Text & "', '" & txtPhone.Text & "', '" & txtYesBox.Text & "', '" & txtOccupation.Text & "', '" & txtEmployer.Text & "', '" & Session("BatchNum") & "', '" & Session("daterec") & "', '" & Session("mydate") & "')"
myconnect = New OleDbConnection(Session("c
myconnect.Open()
mycommand = New OleDbCommand(myinsert, myconnect)
mycommand.ExecuteNonQuery(
this is the error again: Exception Details: System.NullReferenceExcept
and here is code from a nearly identical page with just some different fields. and this code works just fine. this is why i am stumped. it seems like there is something going on when i am trying to set a variable to something. i dont know though. i appreciate you help. here is the other code.
If Me.IsPostBack Then
Dim mydate As String
Session.Add(mydate, "")
Session("mydate") = Format(Now(), "yyyyMMdd")
Session("keyedtotal") = CInt(Session("keyedtotal")
Dim myConnect As OleDbConnection
Dim myCommand As OleDbCommand
Dim myinsert As String
'insert the data
myinsert = "INSERT INTO NoPledgeForm (FName, LName, Apt, Address, City, State, Zip, Amount, Occupation, Employer, Email, BatchNum, ResponseDate, DateKeyed) VALUES ('" & txtFirst.Text & "', '" & txtLast.Text & "', '" & txtApt.Text & "', '" & txtAddress.Text & "', '" & txtCity.Text & "', '" & txtState.Text & "', '" & txtZip.Text & "', " & txtAmount.Text & ", '" & txtOccupation.Text & "', '" & txtEmployer.Text & "', '" & txtEmail.Text & "', '" & Session("BatchNum") & "', '" & Session("daterec") & "', '" & Session("mydate") & "')"
myConnect = New OleDbConnection(Session("c
myConnect.Open()
myCommand = New OleDbCommand(myinsert, myConnect)
myCommand.ExecuteNonQuery(
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
Business Accounts
Answer for Membership
by: emoreauPosted on 2003-10-05 at 08:39:04ID: 9494649
>>into a form called YesPledgeForm
You cannot insert data into a Form. You can only insert data into a TABLE!