473,395 Members | 1,403 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,395 software developers and data experts.

Required Parameters for a command object

Hi, my simple solution is not so simple. I have done a bit of VB
programming, and am now tasked with trying to make access work using
VBA, and battling my butt off. This probably has a really simple
solution, which right now eludes me.

The code is below, and the error message I get is this "No Value given
for one or more required parameters". sClinic is picking up the string
from a combo box, and this does work cos the message box tosses out
the right value.

Private Sub cmdUpdateReport_Click()
On Error GoTo Err_cmdUpdateReport_Click

Dim stDocName As String
Dim AppCmd1 As ADODB.Command

stDocName = "Macro1"
DoCmd.RunMacro stDocName

On Error GoTo Err_cmdUpdateReport_Click

Set AppCmd1 = New ADODB.Command
AppCmd1.ActiveConnection = CurrentProject.Connection
AppCmd1.CommandType = adCmdText
AppCmd1.CommandText = _
"INSERT INTO New_Complete_Data (Facility_Code, ColA, ColB,
ColC, ColD, ColE, ColF, ColG, ColH, ColI, ColJ, ColK, ColL, ColM,
ColN, ColO, ColP, ColQ, ColR)" & _
"SELECT M1C.Facility_Code AS Facility_Code, M1C.C11 AS ColA,
M1C.C12 AS ColB, M1C.C14 AS ColC, M1C.C32, M1C.C43, M1C.C51, M1C.C52,
M1C.C53, M1C.C61, M1C.C71, M1C.C72 AS ColK, M1C.SumDenC16 AS ColL,
M1C.SumC16 AS ColM, M1C.SumDenC82 AS ColN, M1C.SumC82 AS ColO, M1C.C84
AS ColP, M1C.C91 AS ColQ, M1C.C102 " & _
"FROM M1C WHERE M1C.Facility_Code = " & sClinic & " "
MsgBox ("The current clinic code is " & sClinic & ""), vbOKOnly

AppCmd1.Execute

Set AppCmd1 = Nothing

Exit_cmdUpdateReport_Click:
Exit Sub

Err_cmdUpdateReport_Click:
MsgBox Err.Description
Resume Exit_cmdUpdateReport_Click

End Sub

I really appreciate the help.
Jenni
Nov 12 '05 #1
3 4733
"Jenni" <jr*******@khulisa.com> wrote in message
news:db*************************@posting.google.co m...
Hi, my simple solution is not so simple. I have done a bit of VB
programming, and am now tasked with trying to make access work using
VBA, and battling my butt off. This probably has a really simple
solution, which right now eludes me.

The code is below, and the error message I get is this "No Value given
for one or more required parameters". sClinic is picking up the string
from a combo box, and this does work cos the message box tosses out
the right value.

Private Sub cmdUpdateReport_Click()
On Error GoTo Err_cmdUpdateReport_Click

Dim stDocName As String
Dim AppCmd1 As ADODB.Command

stDocName = "Macro1"
DoCmd.RunMacro stDocName

On Error GoTo Err_cmdUpdateReport_Click

Set AppCmd1 = New ADODB.Command
AppCmd1.ActiveConnection = CurrentProject.Connection
AppCmd1.CommandType = adCmdText
AppCmd1.CommandText = _
"INSERT INTO New_Complete_Data (Facility_Code, ColA, ColB,
ColC, ColD, ColE, ColF, ColG, ColH, ColI, ColJ, ColK, ColL, ColM,
ColN, ColO, ColP, ColQ, ColR)" & _
"SELECT M1C.Facility_Code AS Facility_Code, M1C.C11 AS ColA,
M1C.C12 AS ColB, M1C.C14 AS ColC, M1C.C32, M1C.C43, M1C.C51, M1C.C52,
M1C.C53, M1C.C61, M1C.C71, M1C.C72 AS ColK, M1C.SumDenC16 AS ColL,
M1C.SumC16 AS ColM, M1C.SumDenC82 AS ColN, M1C.SumC82 AS ColO, M1C.C84
AS ColP, M1C.C91 AS ColQ, M1C.C102 " & _
"FROM M1C WHERE M1C.Facility_Code = " & sClinic & " "
MsgBox ("The current clinic code is " & sClinic & ""), vbOKOnly

AppCmd1.Execute

Set AppCmd1 = Nothing

Exit_cmdUpdateReport_Click:
Exit Sub

Err_cmdUpdateReport_Click:
MsgBox Err.Description
Resume Exit_cmdUpdateReport_Click

End Sub

I really appreciate the help.
Jenni


1) If this code is failing, why not replace the line AppCmd1.Execute with
Debug.Print AppCmd1.CommandText temporarily so that you can see the SQL
string which it is trying to execute.

2) This should turn up a missing space here ...ColR)SELECT M1C.Facility_Code
AS...

3) There are also no quotes for the string value WHERE M1C.Facility_Code =
MyClinic instead of WHERE M1C.Facility_Code = "MyClinic"

4) Why is sClinic not dimmed? Please don't say you do not use "Option
Explicit"

5) Other, less important points follow:

**Error Handling:
Why is "On Error GoTo Err_cmdUpdateReport_Click" in there twice?

Why don't you label your error handlers with more standard names? Did you
get a wizard to write the code? Wouldn't "On Error GoTo Err_Handler" be
easier than "On Error GoTo Err_cmdUpdateReport_Click"? Not only is it more
readable, but more transferable and less weird if you rename controls - I
would write it like this:

Private Sub cmdUpdateReport_Click()

On Error GoTo Err_Handler

MsgBox "Hi"

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
**Object library
Any special reason you are using ADO code rather than DAO?
** Macros?
DoCmd.RunMacro stDocName
Not many people here use macros - they are simply too limiting

Nov 12 '05 #2
Jenni,
looks like you forgot to put quotes around your variable... I think this line:
"FROM M1C WHERE M1C.Facility_Code = " & sClinic & " "
should be "FROM M1C WHERE M1C.Facility_Code = '" & sClinic & "' "


so when the select statement compiles, it looks like this:

....FROM MIC WHERE M1C.Facility_Code = 'Some Value'

Try that and see if that fixes it.
Nov 12 '05 #3
The string problem solution makes it work, Thanks a million. In
response to the other questions though

1. sClinnic is dimmed as a Private variable at the form level cos it
is picked up in the Lost_Focus event of the combo box.

2. The space thing is not a problem

3. Didn't try the debug.print thing, but will keep it in mind for
future use.

4. Yes a wizard wrote the initial code. I'm new at this, so the wizard
makes it a little easier for me.

5. I use the macro's as it is an inherited project and the macro's do
90% of the work already.

Thanks again. You folks are an absolute fountain of knowledge and
inspiration. I hope I can someone else sometime.

pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
Jenni,
looks like you forgot to put quotes around your variable... I think this line:
"FROM M1C WHERE M1C.Facility_Code = " & sClinic & " "


should be
"FROM M1C WHERE M1C.Facility_Code = '" & sClinic & "' "


so when the select statement compiles, it looks like this:

...FROM MIC WHERE M1C.Facility_Code = 'Some Value'

Try that and see if that fixes it.

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
1
by: PinkGuava | last post by:
Hi, I have a T-SQL stored procedure that returns both output parameters and a recordset. How do I retrieve them in my ASP script? As far as I know, the ADO Command object can be used to retrieve...
6
by: Derek | last post by:
I have an aspx page where I use a reversebind and templates to edit the entire datagrid at one time. I added a textbox and button to change the parameter criteria and then rerun the databind2...
15
by: Fred Zwarts | last post by:
In C++ execution of a program starts already before execution of main(). The initialization of static variables defined outside the scope of main is performed first. I could imagine a program where...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
6
by: BlackMustard | last post by:
hi all, i get a run-time error '424': Object Required on the last line below, and i can't figure out why... Dim adoConn As New ADODB.Connection Dim adoCmd As New ADODB.Command Dim...
0
by: AxleWacl | last post by:
Hi, The below error is what I am receiving. The code im using is below the error, for the life of me, I can not see where any parameter is missing..... Server Error in '/FleetcubeNews'...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.