Ms-access – MS Access: No value given for one or more required parameters

asp-classicms-accessvbscript

I'm trying to run the following query to an MS Access database (from an .asp page) :

SELECT firstname, lastname, emp_id FROM employees ORDER BY firstname

However, I get an error saying

No value given for one or more required parameters.

Now, the query runs fine if I exclude the "emp_id" (primary key) field. I have made sure that the field exists and that there are no typos in the query.

If I run the query through the MS Access GUI, there's a pop-up asking me to enter a "parameter value" for the emp_id field. Could this be why it won't work, and why does it happen?

Getting the employees from the db:

Function GetEmployees()

    Dim employeesRS, sqlGetEmployees, employeesList, e

    Set employeesList = CreateObject("System.Collections.ArrayList")

    sqlGetEmployees = "SELECT firstname, lastname, emp_id FROM employees ORDER BY firstname"

    Set employeesRS = db.connTb.execute(sqlGetEmployees) 'Custom class to simplify db-querying

    While Not employeesRS.EOF

        Set e = new Employee

        e.Firstname = employeesRS("firstname")
        e.Lastname = employeesRS("lastname")
        e.Id = employeesRS("emp_id")

        employeesList.Add(e)

        employeesRS.MoveNext
    Wend

    employeesRS.Close

    Set GetEmployees = employeesList

End Function

Screenshot of table structure: (As you probably noticed, I translated the table and code in my post, to make it more readable . The relationship between code/table fields is identical though. )

enter image description here

Best Answer

Solved:

The query result view in MS Access showed the field name to be "emp_id", but the actual name was "employee_id".

The program using the database used to be an Access-forms application and therefore had different names on the columns in the query result view than the actual names (for some reason, I don't know why that sounded like a good idea)

Related Topic