473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Insert query quit working

I have a query that worked months ago, but after adding additional fields to the target table, the query no longer runs. It took values from text controls on a form. It no longer finds them, so it displays parameter messages instead.

I shortened it up just to test it and even with only one field it doesn't work.

The Patient ID, aka the Me.txt62 field is never null. I have tried setting the focus, but that didn't help.

Short form:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO PatientReferralEditsTable (PatientID) VALUES (Me.txt62)"
Originally, it was in the form:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO PatientReferralEditsTable (PatientID, PhysicianID, PhysicianOfficeID, InsuranceCarrierID, InsuranceCarrierContractID, " & _
  2. "ICD9Code1ID, ICD9Code2ID, ICD9Code3ID, ServiceDiscipline1ID, ServiceDiscipline2ID, ServiceDiscipline3ID, " & _
  3. "PhysicianPhysicianOfficeID, PatientInsuranceCarrierID, PatientReferralID, PatientPhysicianID, PatientPhysicianOfficeID, " & _
  4. "PRICD9Code1ID, PRICD9Code2ID, PRICD9Code3ID,  " & _
  5. "PRServiceDiscipline1ID,PRServiceDiscipline2ID,PRServiceDiscipline3ID) " & _
  6.  
  7. " VALUES (Me.txt62, Me.txt63, Me.Txt64, Me.Txt65,  Me.Txt66), " & _
  8. "Me.Txt67, Me.Txt68, Me.Txt69, Me.Txt106, Me.Txt107, Me.Txt108," & _
  9. "Me.Txt70, Me.Txt71, Me.Txt72, Me.Txt73,  Me.Txt74, " & _
  10. "Me.Txt75, Me.Txt76, Me.Txt77, Me.Txt136, Me.Txt137, Me.Txt138)" 
David
Mar 4 '14 #1

✓ answered by Rabbit

This
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO PatientReferralEditsTable (PatientID) VALUES (Me.txt62)" 
Needs to be this
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO PatientReferralEditsTable (PatientID) VALUES ('" & Me.txt62 & "')" 
Assuming PatientID is a string, if it's a number then leave out the single quotes.

The SQL engine has no idea what Me.txt62 is referring to. You need to append the value, not the reference.

The original form should not have worked either. If that's how the code truly looked, there's no way it should have run without error.

2 1070
Rabbit
12,516 Expert Mod 8TB
This
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO PatientReferralEditsTable (PatientID) VALUES (Me.txt62)" 
Needs to be this
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO PatientReferralEditsTable (PatientID) VALUES ('" & Me.txt62 & "')" 
Assuming PatientID is a string, if it's a number then leave out the single quotes.

The SQL engine has no idea what Me.txt62 is referring to. You need to append the value, not the reference.

The original form should not have worked either. If that's how the code truly looked, there's no way it should have run without error.
Mar 4 '14 #2
NeoPa
32,556 Expert Mod 16PB
How to Debug SQL String will give you the tools and experience to understand what Rabbit's saying more easily.

He's perfectly correct, of course. There must be some misunderstanding as the code you've posted could not possibly work as shown.

When you've played with it a bit you'll appreciate why that is and why working with SQL in VBA can be confusing for so many.
Mar 5 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: johnnyboy10017 | last post by:
I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that...
2
by: avinash | last post by:
hello myself avinash i am developing on application having vb 6 as front end and sql server 7 as back end. when i use insert query to insert data in table then the date value of that query is...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
2
by: GD | last post by:
Hi, There are serveral validation controls in our intranet application. The controls work fine on all of our local machines that have Windows XP professional operating systems on them. After...
5
by: Annie | last post by:
hello guys, I have little experience working with C# and MS Access ... I am having an insert query with one datetime field and a boolean and couple of text and number fields as below: ...
4
by: spam | last post by:
If I run the following query in Access 2002 then I get the expected result: SELECT * FROM CSVImport UNION SELECT * FROM AssetTemp; I get the contents of both tables with no duplicates. If I...
0
by: clickon | last post by:
I want to use an INSERT Query as the value for the UpdateCommand property of an SQL datasource, anyone know if this will actually work ? The reason i want to do it is bacause i am taking values...
1
by: rubinamunir | last post by:
Hi. i need help in insert query . i am working in php and oracle there i need insert datetime.i don't know the format please tell me how can i insert date with time in oracle and wht must...
5
by: deedi | last post by:
Hi everyone, I have a query which will insert records into a table . But when i execute the query in asp, it's not getting inserted in the table (the same query works well in SQL...
1
by: Luqman | last post by:
I have created a Insert Query in Sql Data Source using Oracle Database, with the parameters, and its connected with DetailView Control. When I try to Insert through DetailView Control, Illegal...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.