SQL INSERT -- Asking For Parameters When Executing?!

Jul 22, 2005

Hi all,

I've searched for a solution, and the proposed solution didn't work for me.

I am executing an SQL statement to insert values into a History table when deleting a value in a subform. Two of the 5 values are asking me for parameters when the SQL executes and I cant figure out why! The datatypes they are inserting into are correct and I'm at a loss. The 2 values giving me grief are Manufacturer and Model.

Here's the code:

Dim sSQLMachHistory As String

MsgBox "me.acctid: " & Me.AccountID
MsgBox "me.manufac: " & Me.Manufacturer & " me.serial: " & Me.SerialNumber
MsgBox "model: " & Me.Model

'Insert into History Table:
sSQLMachHistory = "INSERT INTO tblMachineHistory (SerialNumber, Manufacturer, Model, AccountID, MachineID) VALUES (" & Me.SerialNumber & ", " & Me.Manufacturer & ", " & Me.Model & ", " & Me.AccountID & ", " & Me.MachineID & ")"

MsgBox sSQLMachHistory

DoCmd.SetWarnings False
DoCmd.RunSQL sSQLMachHistory
DoCmd.SetWarnings True

My message boxes show me all the values are displaying and should be inserting into the table -- any ideas??? :confused:

cheers

Mike

View Replies


ADVERTISEMENT

Query Results Differ Between Directly Inputting Parameters And Using [Insert]

Sep 12, 2007

I am having a problem getting any results from a query written with a msgbox parameter in the criteria. My query is supposed to look up a project number, and then report various information regarding that number. Here is my problem.

If I type the project number directly in to the "Criteria" cell in Design View it pulls the appropriate results. However, when I put [Enter Project Number] in the "Criteria" cell and insert the same number into the msgbox when I run the query I get no results at all. Any ideas?

View 2 Replies View Related

Executing Query

Oct 15, 2007

Hi there,

I am trying to run a query from an ASP page, which also uses other queries. I get the following error message: [Microsoft][ODBC Microsoft Access Driver] You tried to execute a query that does not include the specified expression 'Expr1' as part of an aggregate function, this is in qrySessionsEverything.


The query name is qrySessionsEverything.
It executes the line:

SELECT * FROM qrySessionsEverything

The queries are below:

qrySessionsEverything
SELECT tblSessions.SessionID AS Expr1, tblSessions.CourseID AS Expr2, tblCourses.CourseName AS Expr3, tblSessions.SessionDate AS Expr4, tblSessions.StartTime AS Expr5, tblSessions.EndTime AS Expr6, tblVenues.VenueID AS Expr7, tblVenues.VenueName AS Expr8, tblVenues.Capacity AS Expr9, tblVenues.Capacity-[bytAttendees] AS bytAvailablePlaces, qrySessionsAccepted.bytAttendees AS Expr10, tblVenues.Link AS Expr11, qrySessionsPending.Pending AS Expr12, [TrainerFirstName] & " " & [TrainerSurname] AS strTrainer, tblSessions.TrainerID AS Expr13
FROM tblTrainers, tblCourses, qrySessionsAccepted, qrySessionsPending, tblVenues, tblSessions
GROUP BY tblSessions.SessionID, tblSessions.CourseID, tblCourses.CourseName, tblSessions.SessionDate, tblSessions.StartTime, tblSessions.EndTime, tblVenues.VenueID, tblVenues.VenueName, tblVenues.Capacity, qrySessionsAccepted.bytAttendees, tblVenues.Link, qrySessionsPending.Pending, [TrainerFirstName] & " " & [TrainerSurname], tblSessions.TrainerID;

qrySessionsAccepted
SELECT tblSessions.SessionID AS Expr1, tblSessions.CourseID AS Expr2, tblSessions.SessionDate AS Expr3, tblSessions.StartTime AS Expr4, tblSessions.EndTime AS Expr5, tblSessions.VenueID AS Expr6, tblVenues.VenueName AS Expr7, tblVenues.Capacity AS Expr8, [Capacity]-[bytAttendees] AS bytAvailablePlaces, Count(qryDelegatesAccepted.DelegateID) AS bytAttendees, tblVenues.Link AS Expr9
FROM tblVenues, tblSessions, qryDelegatesAccepted
GROUP BY tblSessions.SessionID, tblSessions.CourseID, tblSessions.SessionDate, tblSessions.StartTime, tblSessions.EndTime, tblSessions.VenueID, tblVenues.VenueName, tblVenues.Capacity, tblVenues.Link
ORDER BY tblSessions.SessionDate, tblSessions.StartTime;

qrySessionsPending
SELECT tblSessions.SessionID AS Expr1, tblSessions.CourseID AS Expr2, tblSessions.SessionDate AS Expr3, tblSessions.StartTime AS Expr4, tblSessions.EndTime AS Expr5, tblSessions.VenueID AS Expr6, tblVenues.VenueName AS Expr7, tblVenues.Capacity AS Expr8, tblVenues.Link AS Expr9, Count(qryDelegatesPending.SessionID) AS bytPending
FROM tblVenues, tblSessions, qryDelegatesPending
GROUP BY tblSessions.SessionID, tblSessions.CourseID, tblSessions.SessionDate, tblSessions.StartTime, tblSessions.EndTime, tblSessions.VenueID, tblVenues.VenueName, tblVenues.Capacity, tblVenues.Link
ORDER BY tblSessions.SessionDate, tblSessions.StartTime;

qryDelegatesAccepted
SELECT tblDelegates.DelID AS Expr1, tblDelegates.SessionID AS Expr2, tblDelegates.DelTitle AS Expr3, tblDelegates.DelFirstName AS Expr4, tblDelegates.DelSurname AS Expr5, tblDelegates.DelHospital AS Expr6, tblDelegates.DelDepartment AS Expr7, tblDelegates.DelPhone AS Expr8, tblDelegates.DelBleeper AS Expr9, tblDelegates.DelEmail AS Expr10, tblDelegates.DateSubmitted AS Expr11, tblDelegates.Accepted AS Expr12, tblDelegates.Rejected AS Expr13
FROM tblDelegates
GROUP BY tblDelegates.DelegateID, tblDelegates.SessionID, tblDelegates.DelTitle, tblDelegates.DelFirstName, tblDelegates.DelSurname, tblDelegates.DelHospitall, tblDelegates.DelDepartment, tblDelegates.DelPhone, tblDelegates.DelBleeper, tblDelegates.DelEmail, tblDelegates.DateSubmitted, tblDelegates.Accepted, tblDelegates.Rejected
HAVING (((tblDelegates.Accepted)=True) And ((tblDelegates.Rejected)<>True));

qryDelegatesPending
SELECT tblDelegates.DelegateID AS Expr1, tblDelegates.SessionID AS Expr2, tblDelegates.DelTitle AS Expr3, tblDelegates.DelFirstName AS Expr4, tblDelegates.DelSurname AS Expr5, tblDelegates.DelHospitall AS Expr6, tblDelegates.DelDepartment AS Expr7, tblDelegates.DelPhone AS Expr8, tblDelegates.DelBleeper AS Expr9, tblDelegates.DelEmail AS Expr10, tblDelegates.DateSubmitted AS Expr11, tblDelegates.Accepted AS Expr12, tblDelegates.Rejected AS Expr13
FROM tblDelegates
GROUP BY tblDelegates.DelegateID, tblDelegates.SessionID, tblDelegates.DelTitle, tblDelegates.DelFirstName, tblDelegates.DelSurname, tblDelegates.DelHospital, tblDelegates.DelDepartment, tblDelegates.DelPhone, tblDelegates.strDelegateBleep, tblDelegates.DelEmail, tblDelegates.DateSubmitted, tblDelegates.Accepted, tblDelegates.Rejected
HAVING (((tblDelegates.Accepted)<>True) And ((tblDelegates.Rejected)<>True));


Please can you help me.

Thanks,
Bash.

View 1 Replies View Related

Executing Query In VBA

Oct 31, 2007

Hi, I am a beginner in access. I am trying to execute the below query through VBA on a click event on a Command Button in a Form. I am taking input parameter from Form, based on which I want the query result( dynamic Query Parameter).
I getting the attached error message

Please help me out in executing this query in VBA. An example would be of great help. Thanks in advance..

View 14 Replies View Related

Executing Code On Database Open?

Apr 10, 2007

hi,

I was wandering if it is possible to implicitly execute code upon the opening of a database? If so how do I do this? I have code to convert the page settings of a report from a command click but wanted this to be done automatically...

cheers

tania

View 6 Replies View Related

BeforeUpdate Event Executing Too Many Times

Oct 16, 2005

I have a mainform with a search function so the user can select a record to view and update. The selected record is displayed in Subform1 on Page1 of a tab control. The record source of this form is Query1. Page2 of the tab control contains Subform2; record source is the result of Query1 joined to Query2.

The forms correctly displays, updates and adds records my problem occurs when I add VBA code to the BeforeUpdate event of a control on Subform1. The code appears to execute once for each page in the tab control.

Has anyone any suggestions on how I can correct my problem.

Thanks

Fearless

View 3 Replies View Related

Having Trouble In Executing TreeCtrl Code

Jul 11, 2006

Hi,

I am having trouble in implementing the TreeCtrl structure. I have a simple database for testing purpose and I am not able to make it work. There appears to be a problem with the bookmark property and I get an error message:
"can't Add child:Arguments are of wrong Type, are out of acceptable range, or are in conflict with one another".

I have attached the database here and could you please see what is wrong with my code.


Thanks
Priya

View 5 Replies View Related

Executing Command Buttons On Other Forms

Sep 20, 2004

Hi

I have a Visible form and an Invisible (visible=false) form open at the same time. Is it possible to use a button on the visible form to execute the code behind a button in the invisible form. The subroutine on the invisible form is Public. I tried DoCmd.RunCommand and a macro with RunCode but... nada...

(There is a valid reason for this approach but i will spare you the boring explanation. I can think of a work around where I can bypass this need, but this way is cleaner (there are cases where the invisible form is visible and used directly, the form has data which is sent to a report to create a label). I have done everything else with VBA code but for some reason can't get this to work, so now i am obsessed)

Thanks, this forum is really a gem!

View 2 Replies View Related

Executing An Update Command With “'” In The String

Nov 3, 2006

Hi,
I try to execute an update command i.e.:
UPDATE Results set Data = 'Heiner's key' where ValidationNumber = 1 and TestNumber = 2 and Line = 'E1'.
Access does not let me do this because the “'” in Heiner's terminates the update string prematurely.
Does anyone have a suggestion how to do this? Thank you.

View 4 Replies View Related

Create Custom Box Before Executing Query

Jan 9, 2012

I am looking to check, whether i would be able to "add an Message box with a "Message : "Executes all queries all is well.mdb before executing this query ?" , if yes, continue executing the query, else, Exit out of the database?

View 1 Replies View Related

Executing A Query On Periodic Basis At Midnight At 00:05

Oct 31, 2005

I am trying to execute query every midnight at 00:05 and append data into a table. This query reads the data from a linked table and appends the records into the local table.

Access doesn't triggers so I have no clue which way to proceed.

Can anybody help me creating a logic to execute query at midnight?

Regards
Giri

View 2 Replies View Related

Executing A Query On Highlighted Record In Listbox

Jul 25, 2005

How do i apply a query that i want to execute only on a highlighted record in a listbox.

If there is a link, sample database or lines of code could you please assist.

Currently everything is being executed on all of the records in the query.


Also Does Access 2000 support codes for drag and drop forms?

View 2 Replies View Related

Executing A Subforms Procedures From The Parent Form

Dec 19, 2005

is there a way i can call a sub forms procedure from the main parent form.

in other words i have a button command i want to execute

View 2 Replies View Related

Modules & VBA :: Error When Executing OnOpen Report?

Sep 8, 2013

I am using ACCESS 2010, win 7 Home Premium 64bit

difficult to handle error when executing my report. I put a code into OnOpen section but ACCESS states:

Quote:

The expression OnOpen you entered as the event property produced the following error: A problem occurred while Microsoft Access was communicating with the OLE server or ActiveX Control.

Additionally it says in description:

This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs.

I am genuinely confused by that. I have also provided the code in the case if I am missing something I don't know yet. In a debug window, I have executed the code line by line and it worked. Whenever I try to open the report, the error occurs. Should I be aware of something when I write code for reports?

Below, the code in my report "module":

Code:
Private Sub Report_Open(Cancel As Integer)
Call CreateTempTable
End Sub
Private Sub CreateTempTable()
On Error GoTo ErrorHandler
Dim strTable As String

[code]....

View 3 Replies View Related

Storing A Calculation As A String In A Table And Executing It In A Query.

Jun 11, 2007

N.B. This is not your usual 'Bad practice to Store calculated values in a table' post

I have a table of items.
Each item has a different formula attached which I need to store as a literal value in the table and execute it as a normal expression in a query or vb.

e.g

Columns:Item, QTY, Hrs, mins, ItemFormula
Data: Car, 2, 7, 3, [QTY]+ [Hrs]/[mins]

So ' [QTY]+ [Hrs]/[mins]' would literally be stored for that rercod and is how it would be displayed in a table, form, report etc as it is important for the user to see how the calculation is performed as well as seeing the end result which will be calculated as normal in vb or a query.
The formula will vary from record to record.

How do I go about this?

TIA

View 6 Replies View Related

Modules & VBA :: Executing Function Between Business Hours On Weekdays

Sep 13, 2013

What I am trying to do is execute a function M-F every 2 hours between 4am and 6pm. The 2 hour part was easy, I just created a form with a timer, but the other part isn't working so well, here is my latest attempt.

Code:
StrTime = Time()
If Not ((Weekday(Now()) = vbSaturday) Or (Weekday(Now()) = vbSunday)) And (StrTime > "4:00" Or StrTime < "18:00") Then

View 3 Replies View Related

Tables :: Use Insert Into Command To Insert Filepath Into Table That Adds Blank Label

Aug 28, 2014

I am at work, and I have acquired a database that prints labels. They now want the database to be coded so that after certain labels are printed the database will print a blank label. I have the code figured out as a Do While statement in order to print the blank label. The problem I am having is that I am trying to use the Insert Into command to insert the filepath into the table that adds the blank label.

|DoCmd.RunSQL "INSERT INTO Rod_tmakLabels ( Print, [Order] ) SELECT Yes AS Expr1, 'Rods Labels' AS Expr2"|

If I run the above command, it just adds the text "Rods Labels" at the end of the table. Is there anyway with the INSERT INTO command that I can insert the new label between the 2nd and 3rd row and add another row? Or is the command designed only to add a new row to the end? I haven't had any luck searching for this yet.

View 1 Replies View Related

INSERT Query - Insert New Data Only

Jul 2, 2010

Table TBL_NEWDATA is used to append new data to table TBL_PERSON_ALLOCATIONS.

TBL_NEWDATA { Person_ID, Department_ID }
TBL_PERSON_ALLOCATIONS { Person_ID, Department_ID, ... }

I need to devise a query to append data for a particular Department_ID from TBL_NEWDATA to TBL_PERSON_ALLOCATIONS where that data does not already exist there. i.e. for Department_ID 'Research', I would want to append 'Person_ID', 'Department_ID' (in this case: 'Research') to TBL_PERSON_ALLOCATIONS for any tuples not already held.

INSERT INTO TBL_PERSON_ALLOCATIONS (Person_ID, Department_ID)
SELECT Person_ID, Department_ID
FROM TBL_NEWDATA
WHERE TBL_NEWDATA.Department_ID='Form...'

[code]...

This Query takes a single argument from a control (Forms!Main!IN_Department), and this is the Department_ID to be updated.Is there any way to do this using a single query or will I have to use sub queries? I'd hoped not to as to keep the database as concise as possible.

View 2 Replies View Related

Queries :: Insert Into One To Many PK And FK Insert

Mar 25, 2015

I have a normalized DB with one to many relationships, using Primary and Foreign Keys.

I need to do inserts and maintain the PK/FK relationship, which means when I add a new PK I need to insert that PK as FK in other tables in the same transaction.

How do I do this in Access? SQL Server I use transactions, but I can't lock up the tables in Access like that.

I did a bunch of searching and found nothing, which leads me to believe I am way off in my thinking. Below are the dirty details

I have 2 tables, tblName and tblPhone. 1 name can have many phones.

tblName has PKName. tblPhone has PKPhone, FKName.

I have a form where user enters a new Name and PhoneNumber.

Name gets inserted to tblName, assigned with PKName = 100

Phone should get inserted into tblPhone with PKName.

IE Insert into tblPhone (FKName, PhoneNum) VALUES (100,"212-555-1212").

The dumb way I am doing it now is I insert to tblName, query tblname for the PK, then write to tblPhone. This can't be right.

View 2 Replies View Related

Parameters

Mar 16, 2006

I have created a report from the results of a query. The query has 2 parameters.

SELECT Nonconformances.DateRaised, Nonconformances.Customer
FROM Nonconformances
WHERE (((Nonconformances.DateRaised) Between [Enter start date] And [Enter end date])) OR (((Nonconformances.Customer) Like [Enter customer name] & "*"));

Now the problem is that I have been asked to add the search criteria to the report header. If the search criteria came from a form, no problem, but the user enters the criteria into a parameter box generated by the query. So if the start date was 1/5/05 and end date was 31/12/05 and the customer search was F.C, how do I capture this and show it on the report?

Any help appreciated.

View 10 Replies View Related

Parameters!

Sep 1, 2006

Hi

When I want to run a form it prompts me to enter some parameters. I wonder what could have caused this issue?

Any help will be very much appreciated.
B

View 3 Replies View Related

Parameters

Jun 3, 2005

I have a date field. I have
Between [Please enter second begin date] And [Please enter second end date]
as my criteria so that the user may enter two dates. But, I want the extreme dates to be included in my data.

For Example: If the user enters 1/1/2005 and 1/31/2005, I want the information for the 1st and 31st to be included. How can I do this using just about the same criteria statement?

View 8 Replies View Related

Where Are The Parameters?

Nov 29, 2005

Below is a query in SQL view that is driving me crazy.

When ran it ask for a StartDate, EndDate, StartDate, EndDate.

Can someone please look and see if they can determin where the criteria is coming in from. In design view there is no criteria set up to ask for dates. Also, there is no parameter set in the parameters box.




SELECT tblBooksAndContracts.intTrackingNumber, tblGroupInformation.strGroupName, tblGroupInformation.strGroupNumber, tblSystems.ysnSystemWork, tblSystems.dtmSystemWorkComplete, tblGroupInformation.dtmDateMembershipReceived, tblGroupInformation.strRegion, tblBooksAndContracts.ysnNeedBook, tblBooksAndContracts.ysnNeedContract, tblBooksAndContracts.intBookAndContractCarveOut, CompareDates([tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent]) AS [Book Complete], tblBooksAndContracts.dtmContractDistributedToMarke ting AS [Contract Complete], CompareDates([tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent],[tblBooksAndContracts].[dtmContractDistributedToMarketing]) AS [B/C Complete], ([tblGroupInformation.dtmDateMembershipReceived]+[tblBooksAndContracts].[intBookAndContractCarveOut]+30) AS ECD, CompareDates([tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent],[tblBooksAndContracts].[dtmContractDistributedToMarketing],[tblSystems].[dtmSystemWorkComplete],[tblGroupInformation].[dtmDateMembershipReceived]) AS [Master Complete Date], tblGroupInformation.dtmEffectiveDate, tblGroupInformation.strRegion, tblGroupInformation.strNRC
FROM (tblBooksAndContracts INNER JOIN tblSystems ON tblBooksAndContracts.intTrackingNumber = tblSystems.intTrackingNumber) INNER JOIN tblGroupInformation ON (tblSystems.intTrackingNumber = tblGroupInformation.intTrackingNumber) AND (tblBooksAndContracts.intTrackingNumber = tblGroupInformation.intTrackingNumber)
WHERE (((EntryIsComplete([ysnSystemWork],[dtmSystemWorkComplete],[ysnNeedIDCard],[dtmMailIDCards],[ysnNeedBook],[ysnNeedContract],[ysnNeedDraft],[ysnNeedFlyer],[ysnBookAndContractComplete]))=Yes) AND ((IsBetween([startDate],[endDate],[tblBooksAndContracts].[dtmBookShipped],[tblBooksAndContracts].[dtmASODraftsSent],[tblBooksAndContracts].[dtmContractDistributedToMarketing],[tblSystems].[dtmSystemWorkComplete],[dtmMailIDCards],[tblGroupInformation].[dtmDateMembershipReceived]))=Yes));


As well as when it does run, and you enter the span dates, if the field is blank it inputs 12:00 am in the field and includes it in the query. I checked the tables and it is not set up to input 12:00 am as a default value, nor is it stored as 12:00 am in the tables.

I am at my wits end here and any help/advice would be helpful.

If this does't make sense let me know and I will try and explain further.

Thanks in advance!

*please disregard the grammer, I am typing this fast before I head out to get the kids..a mommies job is never done!*:eek:

View 10 Replies View Related

Too Few Parameters.

Sep 21, 2006

Please look at this sql statement and tell me where the error is. When I try to open the recordset, I get a "Too few parameters. Expected 1" error. That kind of error usually goes with missing # on dates or ' on text

DateTime is a DateTime field that defaults to Now().

The problem appears to be in the dates because when I comment out all after the user parameter, it works, and taking out the "AND Used Is Null" doesn't help.

sqlstr = "SELECT * " & _
"FROM tbl_Usage " & _
"WHERE User = '" & UsrNm & "' " & _
"AND DateTime >= #" & Date & "# and DateTime < #" & DateAdd("d", Date, 1) & "# AND Used Is Null"

This is from the immediate window
?sqlstr
SELECT * FROM tbl_Usage WHERE User = 's5ucba' AND DateTime >= #9/21/2006# and DateTime < #9/22/2006# AND Used Is Null

View 1 Replies View Related

Parameters

Sep 4, 2007

Hi

I am using 'Like "*" & [Forms]![Template]![Combo433] & "*"' in a query to a combo box on a form so if I have nothing selected in the combo all data is shown, except this does not show any null values!

Can any advise on how I can adapt this to allow for null values!

Thanks in advance...

View 1 Replies View Related

Parameters Etc

Dec 25, 2007

I have designed an access database for an organisation. The database is basically all the people who work for an organisation, their addresses, the borough they work in and other details. I have deisgned a query that picks out all the people who work in a particular borough, by using parameters. So when I click a button, a box comes up and asks me to put in the borough and voila, I get a list of all the people who work in that borough. But what do I put in the parameter box, if I want the entire list of people in all the boroughs not just one particular borough?

Really appreciate the help...

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved