473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Too few parameters when using strSQL to update field

33 New Member
I'm having a problem with an SQL string that updates a field (RefPhysicianID) in the table TblPatientDemographics. The user navigates through a search, the results are displayed in a list box (in which the bound column is RefPhysicianID in TblRefPhysician), and the following code is used to update the field that links the records between two tables.


Expand|Select|Wrap|Line Numbers
  1. Private Sub BtnSelectPhysician_Click()
  2.  
  3. If MsgBox("Assign physician to patient?", vbYesNo + vbQuestion) = vbYes Then
  4. DoCmd.SetWarnings False
  5.  
  6. Dim strSQL As String
  7. Dim db As DAO.Database
  8.  
  9. Set db = CurrentDb
  10.  
  11. strSQL = "UPDATE [TblPatientDemographics] " & _
  12.     "SET [RefPhysicianID] = Me.LbxPhysicianSearchResults " & _
  13.     "WHERE ([PtID] = "
  14. strSQL = strSQL & [Forms]![FrmPatientDemographics].[PtID] & ")"
  15.  
  16. Call db.Execute(strSQL)
  17. DoCmd.SetWarnings True
  18. End If
  19.  
  20. End Sub

I'm getting a "too few parameters, Expected: 1" Error message. I find this odd because when I used

SET [RefPhysicianID] = Null

in my SQL String, it worked fine (updated the field to Null).

Any ideas on what I'm doing wrong?
Dec 16 '10 #1
4 2432
Delerna
1,134 Recognized Expert Top Contributor
Try this
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE [TblPatientDemographics] " _ 
  2.        & "SET [RefPhysicianID] =" & Me.LbxPhysicianSearchResults & " " _ 
  3.        & "WHERE ([PtID] = " & [Forms]![FrmPatientDemographics].[PtID]
  4.  
Dec 16 '10 #2
JenniferM
33 New Member
Expand|Select|Wrap|Line Numbers
  1.  & "WHERE ([PtID] = " & [Forms]![FrmPatientDemographics].[PtID] & ")"
I had to change the last line to this, but that's only because the string it made was missing a ")"..... Thanks a lot for your help!!
Dec 16 '10 #3
NeoPa
32,556 Recognized Expert Moderator MVP
One of the most popular (frequently occurring rather than best liked) problems we get is with SQL strings being manipulated in VBA code.

The reason this is so difficult is that all the work is being done at a level of redirection. What I mean by this is that the coder is never working directly with the SQL itself, but rather with code which in turn, is relied on to produce the SQL that they are envisaging is required. It's rather similar to the problems coders have historically had dealing with pointers.

Anyway, a technique I often suggest to coders struggling with this (at any level. This happens to experienced coders too.) is to use either the MsgBox() function, or Debug.Print into the Immediate Pane of the debugger window, to display the value of the SQL in the string before using it (That's assuming you're not good with debugging generally. Personally I would trace to the line, then display the value prior to allowing execution of the string - See Debugging in VBA). It's really much easier to appreciate what a SQL string is meant to do, and where there may be problems, when you can see it in its entirety, and in its true form, rather than as the code is about to create it.
Dec 18 '10 #4
mshmyob
904 Recognized Expert Contributor
Good point Neo.

Whenever I build my SQL strings and have a problem I have used the MSGBOX method for years (I also use it to see values of my variables - it is quicker and easier than the immediate window sometimes). It will display the completed SQL string and usually I see that I missed a quote or forgot to put in a space or I am passing a NULL value etc.

Then it is easy to fix.

cheers,
Dec 19 '10 #5

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

Similar topics

1
by: Ryan Hubbard | last post by:
I'm inserting a record into MySQL 4.0 using Visual Basic ADO. When using the AddNew and Update method I am unable to retrieve the value of a Auto incrment field (Yes I know I can MoveLast but this...
1
by: Manolatos Tilemahos | last post by:
Dear friends, First pls accept my apologies, because I am a new Postgres user, so my questions could be silly. We need to setup a database using UTF-8 encoding, however, by some way, we have...
11
by: Lauren Quantrell | last post by:
I already figured out (the hard way) I need to convert all my date parameters into USA format before executing my stored procedures where dates are used as parameters. (Format(StartDate, "m/d/yyyy...
0
by: Harry Leboeuf | last post by:
Hello, I'm swicthing van Delphi to VS2005 with c#. I'm missing the quite easy datamodule from delphi and can't find some general examples on how most people are using the xsd datasources. As...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
1
by: Cerebrus | last post by:
Hi all, Using : .NET 1.1, SQL Server 2000, Win 2K. Could anyone confirm if there is a bug in the SqlDataReader.GetChars() method when using CommandBehavior.SequentialAccess to get a BLOB...
3
by: Ciara9 | last post by:
I am having problems trying to update a field in a database using a field in a form. I currently have two fields, Today and Tomorrow in a table named Date. The Today field automatically defaults to...
8
by: ndeeley | last post by:
Hi! I have data returned from a database displayed on a webpage for amending. A date on the form is selected using a pop-up calendar which returns it to Access. When the date is retrieved the...
3
by: grinder332518 | last post by:
My Form accesses a Query as follows : SELECT tblA.A, tblB.B, tblB.C FROM tblA LEFT JOIN tblB ON tblA.A = tblB.A UNION SELECT tblB.A, tblB.B, tblB.C FROM tblB LEFT JOIN TblA ON ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.