Access Vba Close a Forms Recordset - Download as Excel by ypu19515

VIEWS: 28 PAGES: 7

Access Vba Close a Forms Recordset document sample

More Info
									Compilation Errors These are caused by incorrectly-constructed code or incorrect syntax (grammar).
Tip: always compile all code before attempting to run it.
Tip: always use Option Explicit at the top of all code windows.
             See also this link for further links, FAQs etc, for more errors: http://www.cse.dmu.ac.uk/~mcspence/Access%20and%20VBA%20FAQ.htm

Details (including exact
                             Meaning                                              Possible Corrections
error message)
                                                                                  Check the procedure header. You must pass a parameter value for each
                             You are probably calling a Sub or Function
Argument not optional                                                             required (non-optional) parameter/argument, and the values must be in the
                             procedure incorrectly.
                                                                                  specified order and of the specified datatypes.

                                                                                  Work out carefully which If statement is missing an End If. Make sure your code
Block If without End If      There is at least one End If missing.
                                                                                  is indented correctly as this will help you work out where the End If should go.

                             There is at least one too many End Ifs for this
End If without Block If                                                           Work out carefully which End If is surplus to requirements and delete it.
                             set of If statements.

                                                                                  End of statement: VB wasn't expecting any further code on this line - some
                                                                                  punctuation (such as a comma, quotation marks [or & if concatenating items in
                                                                                  a string]) may be missing. Or this could be a comment and you have forgotten
                             VB was expecting something other than what           the apostrophe (or 'rem') at the beginning of the line.
Expected: <various>
                             was coded here.
                                                                                  List separator or ): VB was expecting something like an & or a close round
                                                                                  bracket at this point.
                                                                                  Then or GoTo: One of these keywords is missing (it's very easy to miss the
                                                                                  Then off the end of an IF statement).
                             All executable VB code should be within a
                             procedure (sub or function). Only non
Invalid outside procedure    executable items such as Dim and Const can be Put the code in an appropriate sub.
                             coded outside a procedure (usually at the head
                             of module, so easy to see).




fd0f29c4-b64f-443b-b2fa-6d325d9bdf76.xls / Compilation                         Page 1 of 7                                               Printed 11/28/2010 at 11:48 PM
Compilation Errors These are caused by incorrectly-constructed code or incorrect syntax (grammar).
Tip: always compile all code before attempting to run it.
Tip: always use Option Explicit at the top of all code windows.
               See also this link for further links, FAQs etc, for more errors: http://www.cse.dmu.ac.uk/~mcspence/Access%20and%20VBA%20FAQ.htm

Details (including exact
                              Meaning                                           Possible Corrections
error message)
                            You are probably declaring a variable with the
Member already exists in an
                            same name as an object method or property           Change the variable name to something that is not a VB keyword. Using
object module from which
                            (e.g. using a VB keyword as a variable name).       prefixes is a good way of avoiding this error.
this object module derives.
                            The Help for this error is actually quite useful.
                          The method or property does not belong to the         If the method/property name is not in the drop-down box then you cannot use it.
Method or data member not object coded. Always use the drop-down box
found                     that pops up when you code; if the name is in         The object name may be misspelled.
                          that box then it's normally correct.                  The method or property name may be misspelled.
                              The item coded is taken to be a Const or          You've probably forgotten to code the Dim or Const keyword.
Statement invalid outside
                              variable declaration, but it has been coded
Type block                                                                      If you're using Type, then you've not coded it correctly.
                              incorrectly.
                              VB cannot find a sub or function procedure with Correct spelling error for the Call statement procedure name.
Sub or Function not defined
                              this name.                                       Set procedure in Access module to Public
                                                                               A keyword may be missing or incorrectly spelled.
                              VB can't work out exactly what is wrong, but     Punctuation may be incorrect. (e.g. a missing <space><underline> for a code
Syntax Error                  knows something is. The code does not conform statement written over several lines, or an & missing for a string concatenating
                              to the rules of the language.                    several items).
                                                                               Other spelling error.
                              VB cannot find a variable declaration (Dim or    Correct the spelling for the variable/Const/field name.
Variable not defined          Const statement, or form/report field) with this
                                                                               Set variable/Const in Access module to Public
                              name.




fd0f29c4-b64f-443b-b2fa-6d325d9bdf76.xls / Compilation                      Page 2 of 7                                                 Printed 11/28/2010 at 11:48 PM
Compilation Errors These are caused by incorrectly-constructed code or incorrect syntax (grammar).
Tip: always compile all code before attempting to run it.
Tip: always use Option Explicit at the top of all code windows.
             See also this link for further links, FAQs etc, for more errors: http://www.cse.dmu.ac.uk/~mcspence/Access%20and%20VBA%20FAQ.htm

Details (including exact
                             Meaning                                         Possible Corrections
error message)
                                                                             Check the procedure header. You must pass a parameter value for each
Wrong number of
                             You are probably calling a Sub or Function      required (non-optional) parameter, and the values must be in the specified
arguments or invalid
                             procedure incorrectly.                          order and of the specified datatypes. If the procedure does not require any
property assignment
                                                                             parameters then you should not provide any when calling it.




fd0f29c4-b64f-443b-b2fa-6d325d9bdf76.xls / Compilation                    Page 3 of 7                                              Printed 11/28/2010 at 11:48 PM
Run-Time Errors These are caused by correctly-constructed (compiled) code.
Each line of the code compiles, but the code does not 'work' together correctly and fails at run-time.
If you have not compiled your code before running then the error may actually be a compilation error! (see other worksheet).

Details (including exact
                               Meaning                                                 Possible Corrections
error message)
                               "You passed an invalid parameter in your                Use the Debugger to look at the values in the parameters at run-time. One (or
                               procedure call. This could be because the               more) of them will have an invalid value, for example a wrong datatype, or a
5: Invalid procedure call or   parameter was out of range, or contained invalid        negative value when only positive values are expected. Then look at, and
argument                       data."                                                  correct, the code that sets the values. Check that you have listed parameters in
                               http://www.vbscriptonline.com/errors/runtime/Invalid-
                                                                                       the correct order.
                               procedure-call-or-argument.asp
                                                                                       Check the value to be assigned - is this the value you are expecting, or is it Null,
                                                                                       the empty string, some other incorrect (and unexpected) value? If it's not as
                                                                                       expected then investigate code (perhaps using the Debugger) to see why this
                                                                                       is.
                               You are trying to assign a value to a variable          Check the datatype of the destination variable - has this been set to an incorrect
                               which has an incompatible datatype; for                 datatype? If so, then change it to something more appropriate.
13: type mismatch.
                               example, an alphanumeric string value to a              This error can also occur when you open a form if you are using a control
                               numeric datatype.                                       property incorrectly. A common mistake is to confuse the confuse the combo
                                                                                       box properties of ColumnWidth (the full width of the combo list) and
                                                                                       ColumnWidths (the widths of each column in the list).
                                                                                       If you are calling a procedure, check that you have the parameter values in the
                                                                                       correct order and of the correct datatypes.
                                                                                       Code the Set statement for the database so that it is executed before the Open
                               DAO code - you have not run a Set statement             Recordset statement. This error can also occur after a run-time failure, when
                               for the database before attempting to run an            you attempt to resume running the code, as the error may have broken the
                               Open Recordset statement.                               connection with the database - in this event, close the form(s) down and start
91: object variable or With
                                                                                       again.
block variable not set.
                               With block (see VBA Trainer section 7.7) - you
                                                                                    Rewrite the With code and associated code so that the construction is now
                               have not constructed the block correctly or are
                                                                                    correct.
                               attempting to transfer control to a point within it.




fd0f29c4-b64f-443b-b2fa-6d325d9bdf76.xls / Run-Time                                Page 4 of 7                                                 Printed 11/28/2010 at 11:48 PM
Run-Time Errors These are caused by correctly-constructed (compiled) code.
Each line of the code compiles, but the code does not 'work' together correctly and fails at run-time.
If you have not compiled your code before running then the error may actually be a compilation error! (see other worksheet).

Details (including exact
                                Meaning                                              Possible Corrections
error message)
2102: the form name
'<name>' is misspelled or       VB can't find the form you are attempting to         Check the names of your forms, find the form you meant to open and correct
refers to a form that doesn't   open.                                                the name in the DoCmd.OpenForm statement.
exist.
                                You are trying to set the Enabled property of a
2164: "you can't disable a      control (perhaps a command button) to False          Move the cursor somewhere else (to another button, or a textbox, for example)
control while it has the focus" while the cursor is on the control (perhaps the      before the code to set the Enabled property. Use the SetFocus method.
                                user has just clicked on this button).

                                                                                     If this has occurred in code in a report Detail_Print event then it is very likely that
                                                                                     the table/query upon which the report is based has not returned any data - i.e.
                              You are trying to access a value in a bound
2427: "you entered an                                                                the report is 'empty'. (But I have no idea why the Detail_Print event is then
                              field, but there is no record (and thus data)
expression that has no value"                                                        invoked!). Section 5.5 of the 'Getting Started' VBA Trainer shows how to use the
                              available (I think that's what this means…).
                                                                                     Report_NoData event to detect an empty report and avoid this error.
                                                                                     http://www.cse.dmu.ac.uk/~mcspence/Access.htm#VBA Trainers
                                If this error occurs with DAO code for a
3027: "cannot update -
                                recordset then the problem may be that SQL for       See VBA FAQ 27 on
database or object is read-
                                the recordset results in a query that cannot be      http://www.cse.dmu.ac.uk/~mcspence/Access%20and%20VBA%20FAQ.htm
only"
                                used to update a table.
                                You may be referencing a field in a table,           Correct the field name so that it matches the table name exactly. Take care with
                                possibly using a Recordset, but have made a          names with characters such as <space> and # - these names must be enclosed
3061: Too few parameters.
                                typo in the field name.                              in square brackets [ ].
Expected 1.
                                SQL error where a string value has not been
                                                                                     Add the quotation marks.
                                enclosed in quotation marks.
                                                                                     A common mistake is, when building up the SQL in code over several lines,
3131: Syntax error in FROM      There is an error in the FROM clause of the
                                                                                     forgetting to code spaces between words at the end of one line or the
clause.                         SQL that VB is attempting to run.
                                                                                     beginning of the next. So check for, and add, spaces.




fd0f29c4-b64f-443b-b2fa-6d325d9bdf76.xls / Run-Time                               Page 5 of 7                                                  Printed 11/28/2010 at 11:48 PM
Run-Time Errors These are caused by correctly-constructed (compiled) code.
Each line of the code compiles, but the code does not 'work' together correctly and fails at run-time.
If you have not compiled your code before running then the error may actually be a compilation error! (see other worksheet).

Details (including exact
                                Meaning                                                 Possible Corrections
error message)
                                                                                        This occurred for two students who were attempting to use the FindFirst method
                                                                                        for a recordset. When declaring the recordset the second parameter had been
3251: Operation is not          You are using a property or method that is not          omitted. In Access 2003 (or earlier) this did not matter as the default was
supported for this type of      available at this time (though the line that fails      dbOpenDynaset. However, these databases were created with Access 2007. It
object                          has compiled).                                          may be that the Access 2007 default is now something else. So code the open
                                                                                        command as: set rstName = dbName.OpenRecordset("tblName",
                                                                                        dbOpenDynaset)
3265: Item not found in this DAO code references a table field that doesn't             Correct the spelling of the field name - look for embedded spaces (or not) or
collection                   exist.                                                     hyphens, underlines, etc.
                             The dialog box will normally show the name of a
Dialog box: 'Enter Parameter
                             table and field in that table. But the table field find the SQL code and correct the incorrect field name.
Value'.
                             name is incorrect.
Dialog Box: The record          VB can't find the data you have specified. Read
source '<SQL details>'          the rest of the message as this suggests some Check the table name specified in the FROM clause of the SQL - this may be
specified on this form or       causes. This error can also occur if the SQL for misspelled or incorrect.
report does not exist.          a combo or list box is incorrect.
Dialog box: Syntax error        The SQL is incorrect - it does not conform to           If you have built up the SQL in bits in a string variable then you may have
(missing operator) in query     the correct SQL syntax (spelling, grammar and           missed spaces at the end/beginning of lines, so that words and values run into
expression 'SQL statement '     punctuation)                                            each other. Check for, and add, spaces.
The expression <event
name> you entered as the
                                You have probably attempted to run your code
event property setting                                                                  Compile your code and remove all errors! Then run the test again.
                                without clean-compiling first.
produced the following error:
<text for the error>.




fd0f29c4-b64f-443b-b2fa-6d325d9bdf76.xls / Run-Time                                  Page 6 of 7                                             Printed 11/28/2010 at 11:48 PM
Logic Errors These are caused by correctly-constructed (compiled) code.
Each line of the code compiles, but the code does not 'work' together correctly and causes incorrect results, but no failures.
You will almost certainly need to use the Debugger to step through code to see what's going on and why.
There's an infinite number of errors in this category! Some common ones are listed below.


Details                         Possible Corrections

Combo box is blank although SQL does not select any rows - try the SQL in a separate query to see what it returns.
SQL to populate it has been SQL has not been put into the combo box RowSource property.
coded.                      SQL has not been put into the correct variable.
Combo box has duplicate
                            Use DISTINCT in the SQL or query behind the box. (SELECT DISTINCT…)
rows.
Unexpected error message of
                            Check the condition(s) under which this message is generated - perhaps you have the condition(s) the wrong way round.
own.
Command button click does Is there any code behind it?
not do anything             Has the code been linked to the event in the button property box? (see Event tab in properties).
                            You cannot use Count, Sum or similar in a textbox ControlSource property in a page footer (group footers and report
Total in page footer for a
                            footers are OK). You will need to use VBA code in the Page Header Print and Detail Print events to add up the required
report shows as #Error.
                            values.

								
To top