MS Access runtime error '3061' too few parameters expected 2
Try this:
sSQL = "SELECT Count(*) AS [CountOfScheduleB] " & _
"FROM [BFMA_TaskList] INNER JOIN [Reviews_Programme] ON [BFMA_TaskList].[Task] = [Reviews_Programme].[Task] " & _
"WHERE [BFMA_TaskList].[Schedule]=""B"" AND [Reviews_Programme].[Planned_Date] Between #" & Format(Me![txtstatsfrom],"mm\/dd\/yyy") & "# And #" & Format(Me![txtstatsto],"mm\/dd\/yyy") & "#;"
MS Access OpenRecordset and too few parameters issue
try the syntax: qry.Parameters("BeginDate").Value = Forms![Run]![textBeginOrderDate]
You can also add a line with debug.print Forms![Run]![textBeginOrderDate]
to make sure it is the value you expect.
https://stackoverflow.com/a/24535025/78522
Another possibility is to modify the query and use for example[Forms]![Run]![textBeginOrderDate]
as a criteria
MS Access SQL Too Few Parameters: Expected 2
sqlQuery = "SELECT [My_Sheet].* " & _
" INTO My_New_Sheet" & _
" FROM [My_Sheet] " & _
" WHERE [Some_Field] = '" & [Some_Possible_Value_For_The_Field] & "'" & _
" ORDER BY Rnd(-(100000*" & [Some_Other_Field] & ")*Time())"
Debug.Print sqlQuery
CurrentDb.Execute sqlQuery
When you use a form variable, the value has to be read from outside of the SQL statement. Hence why we close the statement with double quote, add the field value, and then continue by opening the with a double quotes again.
Notice that you need to keep the field qualifiers. In this case I assumed your first field was a string which requires the single quote qualifiers and the second variable as an integer which doesn't require qualifiers.
INSERT INTO Too few parameters
Your SQL string contains:
INSERT INTO [tb_dies] ([TOOL_ID], [DESCRIPTION], [RACK], [COLUMN], [COMMENTS])
VALUES (-1,temp,temp,12,temp,temp)
Which isn't valid SQL - right now the database server will consider those occurrences of temp
to be a variable or column name; the temp
probably needs to be in single apostrophes (meaning "a string"), like this:
INSERT INTO [tb_dies] ([TOOL_ID], [DESCRIPTION], [RACK], [COLUMN], [COMMENTS])
VALUES (-1,'temp','temp',12,'temp','temp')
Hence you probably want your VB to be:
tempStr = "'test'"
PS; being MS Access, there's a chance that standard SQL wont work, and that single apostrophes aren't used for strings. If it's double quotes "
to denote a string in access, you'll be looking at VBlike:
tempStr = """test"""
The commenters make valid points; you shouldn't use string concatenation to build SQL queries.. It's worth having a read through http://bobby-tables.com right now to get some background info on why it's bad, and then you'll be better equipped to embark down a path of software development that avoids writing software susceptible to this particular (and common) form of hacking
odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect
First, your sql command must evaluate to something like this:
CHECKTIME BETWEEN #2021/09/28 00:00:00# AND #2021/09/29 23:59:59#
Thus, try:
$from_date = date('Y/m/d', strtotime($_REQUEST['from_date'])) . ' 00:00:00';
$to_date = date('Y/m/d', strtotime($_REQUEST['to_date'])) . ' 23:59:59';
$query = "INSERT INTO CalculateData (USERID, [Name], lastname, CardNo, DEPTID, DEPTNAME, SUPDEPTID, datein, timein, dateout, timeout) SELECT USERID, [Name], lastname, CardNo, DEPTID, DEPTNAME, SUPDEPTID, Format(CHECKTIME, '\#yyyy/mm/dd\#') AS datein, FORMAT(MIN(CHECKTIME), '\#h:m:s\#') AS timein, Format(CHECKTIME, '\#yyyy/mm/dd\#') AS dateout, FORMAT(MAX(CHECKTIME), '\#h:m:s\#') AS timeout
FROM TransactionLog WHERE CHECKTIME BETWEEN #$from_date# AND #$to_date#
GROUP BY USERID, [Name], lastname, CardNo, DEPTID, DEPTNAME, SUPDEPTID, CHECKTIME";
You could also try this simpler approach:
SELECT USERID, [Name], lastname, CardNo, DEPTID, DEPTNAME, SUPDEPTID, DateValue(CHECKTIME) AS datein, TimeValue(MIN(CHECKTIME)) AS timein, DateValue(CHECKTIME) AS dateout, TimeValue(MAX(CHECKTIME)) AS timeout
Related Topics
How to Select All Values and Hide Null Values in SQL
Join Two Tables Based on Relationship Defined in Third Table
How to Select the Set of Rows Where Each Item Has the Greatest Timestamp
Update Xml Tag in a Clob Column in Oracle
How to Group by the Each Week Upto Last Six Week Sundays Dates in SQL
Query Grants for a Table in Postgres
Sp Taking 15 Minutes, But the Same Query When Executed Returns Results in 1-2 Minutes
SQL Server 2008 Unique Column That Is Case Sensitive
Sqlite: Count Slow on Big Tables
Save Output from SQL Function to CSV File (Copy) with Dynamic Filename
Postgresql - Query from Bash Script as Database User 'Postgres'
Access SQL Query: Find the Most Recent Date Entry for Each Employee for Each Training Course
How to Add Multiple "Not Like '%%' in the Where Clause of SQLite3
Delete Statement in SQL Is Very Slow
Why Does SQL Server Return 0 for 1/2