I want to use find command for searching file in the database, but if I add "and" command i received error. It is possible to use and in Find command

I try to this syntax but it is error

.Open "Select *From salary'", strconek, adOpenStatic, adLockOptimistic
.Find "empno = '" + vempno + "'" and "salary_month = '"smonth"'", 0, adSearchForward
if not (.eof)
msg existing
else
accept data
endif

Anybody can help me to fix this error or anyone have idea what command to use for searching a file.. The main purpose of me is to chech the employeenumber and salaryofthemonth if existing or not..

what command I will use to seek both employee number and salaryofthemonth as joint conditional statement for searching file in the database.

thanks in advance

Recommended Answers

All 2 Replies

You're already using the query so why not maximize the usage of it?

" Select * From Salary Where empno = '" & vempno & "' And salary_month = '" & smonth & "'  "

you can't use find method on more than one column. ADO's Recordset.Find method works on one column, and one column only. why do you want to use Find? Although it is appropriate in some situations, using it to locate records is generally very inefficient, in terms of speed and memory. Find works by examining each record in a Recordset for the criteria you give it after you have created the Recordset and retrieved all the data from your database. Retrieving lots of unwanted records, particularly down the wire from a server, when you are really interested in only a handful, or sometimes just one row of data. This creates a lot of unnecessary overhead. Unless you have a very compelling reason for using Find, I'd recommend using an alternative approach, like filtering your Recordset or using SQL, for serious performance gains.

The Recordset.Filter method filters out records that don't match one or more criteria. You can specify multiple conditions in a filter by using 'AND' or 'OR', so using Filter would allow you to check multiple columns. For example, suppose we open a Recordset and execute the following code:

rs.Filter "Country='India' and Place='Delhi'"

The Recordsetrs would then contain only records where the Country and Place fields were India and Delhi, respectively. If no records existed that match these criteria, rs would be empty, with rs.EOF and rs.BOF both true. To remove a filter from a Recordset, set the Filter property to an empty string ("") or the constant adFilterNone.

OR Lastly use a SQL SELECT statement to ensure that the Recordset contained only records with the values you are looking for. SQL processing is done by the data provider and is generally the fastest way to retrieve a restricted set of data because the only real overhead is the opening of the Recordset, which you have to do anyway.


Regards
Shaik Akthar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.