Well, it won't show a message to the user, but it will restrict their choice to the options in the combobox.
If you want to do a message, then these lines:
Private Sub YourComboBox_NotInList((NewData As String, Response As Integer)
MsgBox "The selection is wrong.", vbExclamation +...
Is this combo in a table field or on a form?
If a form, then you can set the combobox's LimitToList property to Yes and, in the OnNotInList event, the following:
Response = acDataErrContinue
First things first: are you replicating these spreadsheets like for like in an Access table, or have you taken the necessary steps to design/normalise your data into a set of tables in Access?
Perhaps evaluate the user input in your control's BeforeUpdate property.
i.e.
Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
If Me.YourTextBox > Me.TheQuantity Then
MsgBox "That's too much stock for the quantity", vbExclamation + vbOkOnly, "Too Much Stock"
Cancel...
If you're getting the Too Few Parameters error then it's likely you're going to have to look into the QueryDef object and its Parameters collection, as it sounds like the queries you are trying to open need their parameters defined.
Answering my own questions now.
Basically, here's my new AppForm class.
Option Compare Database
Option Explicit
Private WithEvents frm As Access.Form
Public Sub SetAttributes(ByRef param_frm As Form)
Set frm = param_frm
With frm
' some general form attributes...
Okay, I'm sick of designing forms whereby I have to go through their individual settings and set things like PopUp to True or RecordSelectors to False.
Therefore I want to create a form class that, in the Form_Open event will do all that form me for every form.
So, I've got a class called...
Bit messy, as just cobbled it together, but this may help.
Personally, I think it would be better if the forename and surname were stored in separate fields.
Dim rs As DAO.Recordset
Dim myVar As WhateverTypeItShouldBe
Set rs = CurrentDb.OpenRecordset("YourQuery")
myvar = rs.Fields(Whatever Field Number It Is)
rs.Close
Set rs = Nothing
Your SQL can't be found because the OpenQuery method is looking for a query. It doesn't recognise your SQL as the name of a query in your database.
Time to look into the QueryDef object.
For info, the SQL you built was a SELECT query. All it does is select some records.
The command you used was DoCmd.RunSQL. This supposes the query will perform an action. Actions include UPDATE, INSERT, DELETE. They do not include SELECT.