This problem occurs most when you are working on the student information management system over the past few days. "Real-time error '91 ': the object variable or with block variable is not set ". As shown in the right figure:
When we encounter this problem, we should first refer to msdn, but at this time, msdn does not seem to help us a lot. To sum up, there are actually many situations of this error:
1. Before running the program, the ODBC data source or ODBC data source configuration error is not configured. Of course, the premise is that SQL Server executes the relevant SQL code (student. MDB file used in the student system ).
2. Code problems. In most cases, the query statement is faulty, for example:
(1) There is no space between SQL statements: txtsql = "select * fromstudent_info"
(2) In the form that executes the query of student status information, execute the statement txtsql = "select * From result_info where". Because conditions need to be added later'
.
(3) In a complete query statement, for example, txtsql = "select * From class_info where class_no = '" & trim (txtclassno. text) & "'", when determining the conditions in the input box at last, double quotation marks and single quotation marks must be noted (the quotation marks of the entire sentence are divided into three layers from the outside to the inside: Double quotation marks, single quotation marks, double quotation marks (double quotation marks.
3. Logic error: the statement is missing. After correctly assigning values to the execution statement txtsql, you can directly operate on the data in the database. In other words, you can operate on the execution statement without connecting to the database, this is also my mistake. After assigning values, you can directly add, delete, modify, and query the database, leaving the executesql function for calling and determining and connecting to the database completely behind.
4. There are also prompts in msdn. For example, the object variable you are trying to use has been set to nothing. I will not talk about it more here. For details, refer to msdn for VB6.0.