473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Check recordcount -table in Ms access(local)

22
Hi all,

I am in the process of developing a small Access application. i have the table locally in Access and I am using the following code to get the recordcount ( or to check if any record exists), but when i check for rst.eof condition, it is always true..but when i actually run the query i see, many rows returned, i m not clear about how to specify the connection parameter with the recordset, as i m using the tables locally, but i think something is wrong with the ADODB connection???

[code starts here]

Private Sub Process_Click()
Dim rcst As New ADODB.Recordset
Dim Con As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set Con = CurrentProject.Connection

If Frame160 = 1 Then

query1 = "select * from Table a where DMNum LIKE '" & Textboxentry& "*'"
rst.Open query1, Con, adOpenDynamic, adLockOptimistic
If rst.EOF = True Then

MsgBox " No Records Available for this search"
Textboxentry.Text = ""
rst.Close
Call Form_Load
Exit Sub

Else

query1 = "select * from Table a where DMNum LIKE '" & Textboxentry& "*'"
Me.Mysubform.Form.RecordSource = query1
Form_Myform.Textboxentry= Clear
Form_Myform.Textboxentry.SetFocus
Textboxentry= ""
rst.Close

End If

ElseIf Frame160 = 2 Then
....................
................
End If
End Sub
[code ends here]

Is there anyother way that i can check for recordcount for the Query1?


Any help is highly appreciated.
Thanks so much in advance....
Feb 13 '08 #1
4 2625
FishVal
2,653 Expert 2GB
Hi, jaishu.

Just two suggestions.
  • get a runtime value of query1 variable and try to execute in Query builder
  • try to use "%" wildcard instead of "*"

Regards,
Fish
Feb 13 '08 #2
ADezii
8,834 Expert 8TB
Hi all,

I am in the process of developing a small Access application. i have the table locally in Access and I am using the following code to get the recordcount ( or to check if any record exists), but when i check for rst.eof condition, it is always true..but when i actually run the query i see, many rows returned, i m not clear about how to specify the connection parameter with the recordset, as i m using the tables locally, but i think something is wrong with the ADODB connection???

[code starts here]

Private Sub Process_Click()
Dim rcst As New ADODB.Recordset
Dim Con As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set Con = CurrentProject.Connection

If Frame160 = 1 Then

query1 = "select * from Table a where DMNum LIKE '" & Textboxentry& "*'"
rst.Open query1, Con, adOpenDynamic, adLockOptimistic
If rst.EOF = True Then

MsgBox " No Records Available for this search"
Textboxentry.Text = ""
rst.Close
Call Form_Load
Exit Sub

Else

query1 = "select * from Table a where DMNum LIKE '" & Textboxentry& "*'"
Me.Mysubform.Form.RecordSource = query1
Form_Myform.Textboxentry= Clear
Form_Myform.Textboxentry.SetFocus
Textboxentry= ""
rst.Close

End If

ElseIf Frame160 = 2 Then
....................
................
End If
End Sub
[code ends here]

Is there anyother way that i can check for recordcount for the Query1?


Any help is highly appreciated.
Thanks so much in advance....
Expand|Select|Wrap|Line Numbers
  1. Private Sub Process_Click()
  2. Dim rcst As New ADODB.Recordset
  3. Dim Con As New ADODB.Connection
  4. Dim rst As New ADODB.Recordset
  5.  
  6. Set Con = CurrentProject.Connection
  7.  
  8. If Frame160 = 1 Then
  9.   query1 = "select * from Table a where DMNum LIKE '" & Textboxentry & "*'"
  10.   rst.Open query1, Con, adOpenDynamic, adLockOptimistic
  11.     If Not rst.BOF And Not rst.EOF Then     'valid Record(s) exist
  12.       query1 = "select * from Table a where DMNum LIKE '" & Textboxentry & "*'"
  13.         Me.Mysubform.Form.RecordSource = query1
  14.         Form_Myform.Textboxentry = Clear
  15.         Form_Myform.Textboxentry.SetFocus
  16.         Textboxentry = ""
  17.           rst.Close
  18.     Else
  19.       MsgBox " No Records Available for this search"
  20.       Textboxentry.Text = ""
  21.         rst.Close
  22.         Call Form_Load
  23.           Exit Sub
  24.     End If
  25. ElseIf Frame160 = 2 Then
  26. ....................
  27. ................
  28. End If
  29. End Sub
P.S. - Have a look at this Link also:
How to check for an Empty Recordset
Feb 14 '08 #3
jaishu
22
Hi Fishval and Adezii,

Thank you very much, yes it works now.. i used both your techniques
used " % " instead of " * " when checking EOF condition, and for requery(when record exists to populate values) used the ' * '.
It worked, but any reason why * did not work for EOF/BOF checking and only % worked?????

BUT THANK YOU SO MUCH FOR CORRECTING THE FLOW OF CODE,
Really appreciate your help!!!


Bye,
Jaishu
Feb 15 '08 #4
FishVal
2,653 Expert 2GB
Hi, Jaishu.

Read ANSI Standards in String Comparisons article.

Regards,
Fish
Feb 15 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Colin J. Williams | last post by:
I have material on a local PC which I upload to a web server. I would like to use webchecker to check both the local linkage and that at the remote server. All works well when I check the...
1
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
13
by: Niki Kovacs | last post by:
Hi, I'm an Austrian writer living in Montpezat (South France). I just installed a local W3C validator on my machine (Slackware 10.1, local Apache server). It's accessible as...
9
by: Stefan Turalski \(stic\) | last post by:
Hi, I done sth like this: for(int i=0; i<10; i++) {...} and after this local declaration of i variable I try to inicialize int i=0;
1
by: BuddyWork | last post by:
Hello, I need to know how I can check if the drives on my machine are network drives and local drives via the .Net framework. For example my PC has the following drives C: Local D: Local N:...
9
by: Sameh Ahmed | last post by:
Hello there Is there a way through dotNet to check if a certain user is a member of a specific group? I use ADSI to get the memberships of the user then compare them to the group I want to check,...
3
by: Indiresh | last post by:
Hi all, I have a problem downloading web pages to my local system. I am using the HttpebRequest class to query a web site and get the response from the same. UndNow, when i asy a web page, all...
1
by: orp | last post by:
We've been struggling on how to determine if a local user is already in a local group. We have code (C#) that creates a local user, if the user doesn't already exist. And, we have code (C#) that...
2
by: Jerad Rose | last post by:
I have a fairly simple C# console app which copies files from a network folder to a local folder. When the app resides on my local C: drive, it runs just fine. However, when the app resides on a...
22
by: Laura T. | last post by:
In the following example, c# 2.0 compiler says that a3 and ret are used before assigned. as far as I can see, definite assignment is made. If I add finally { ret = true; a3 = "b3";
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.