473,395 Members | 1,452 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,395 software developers and data experts.

Recordset can not move to other records, need some help!

I have problem when open the record set as below code :

Private Sub Text4_LostFocus()
Dim dbs As Database
Dim rs As Recordset
Dim sql As String
On Error Resume Next
Set dbs = CurrentDb()
sql = "select * from tbl_InsertPicture where pname = '" & Text4 & "'"
Set rs = dbs.OpenRecordset(sql)
rs.MoveLast
rs.MoveFirst
Text8 = rs.RecordCount
Text6 = rs!card
rs.Close
End Sub


Data in Table tbl_InsertPicture
ID card fname lname
1 31001 A X1
2 31002 B X2
3 31005 C X3
4 31009 D X4
5 31100 B X5
6 31111 C X6

Text4 serch the name "C", in form show text6 = 31005 and text8 = 2 that but when I click next on the navigator button form still show text6 = 31005 but acctually text6 have to show 31111, I don't understand why the record are not able to move to other records.

Please help me, what wrong on my code and how to solve this problem.

Thank you very much.
Nov 16 '06 #1
4 1823
NeoPa
32,556 Expert Mod 16PB
Try setting a breakpoint at the beginning of your code and tracing through it (use F8 to step or Shift-F8 to step over lines, regardless of procedure calls within a line).

See if the code is actually being executed.
See what the settings are in the code when you step through.
Nov 16 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
You are not actually moving through the records either in the recordset or in the form. My instinct says there is a better way of doing what you are trying to do. But, to follow your design you will need the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Text4_LostFocus()
  3. Dim dbs As Database
  4. Dim rs As Recordset
  5. Dim sql As String
  6. Dim i As Integer
  7. On Error Resume Next
  8.  
  9.   Set dbs = CurrentDb()
  10.   sql = "select * from tbl_InsertPicture where pname = '" & Text4 & "'"
  11.   Set rs = dbs.OpenRecordset(sql)
  12.   rs.MoveLast
  13.   rs.MoveFirst
  14.   Me.Text8 = rs.RecordCount
  15.  
  16.   For i=1 To rs.RecordCount
  17.     Me.Text6 = rs!card
  18.     rs.MoveNext ' will move to the next record in the recordset
  19.     ' this will move to the next record in the form
  20.     DoCmd.GoToRecord acDataForm, "YourFormName", acNext
  21.   Next i
  22.  
  23.   rs.Close
  24.   Set rs = Nothing ' always reset the recordset
  25.   Set db = Nothing ' always reset the database
  26.  
  27. End Sub
  28.  
  29.  
Nov 16 '06 #3
nico5038
3,080 Expert 2GB
When you have a bound form to the table it's better to use the filter to select a subset of rows.
This works e.g. behind a [Filter] button besides the [txtValue] field like:

' Test field is filled
if len(nz(me.txtValue))> 0 then
' set the fiter by supplying the fieldname and (here with surrounding single quotes as it's a text field) the value to filter for
me.filter = "Code='" & Me.txtValue & "'"
' activate the filter
me.filteron = true
else
' no value, so deactivate the filter
me.filteron = false
endif

Getting the idea ?

Nic;o)
Nov 16 '06 #4
PEB
1,418 Expert 1GB
It seems that u use unbound form...

Once u use a bound form the number of records are in the left bottom
the curreent recorsd is also mentionned and Your respective card is displayed in the bound field for it!

So assign in the form properties RecordSource your table names

In your text 4 set the field Card as control Source property

And navigate with the boutons in the bottom left...

if you want to do your own navigation you can do it using wizards!
Nov 18 '06 #5

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

Similar topics

9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
3
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
7
by: tdr | last post by:
I need to compare table 1 to table 2 and if the row/recordset in table 1 is different from table 2, write the entire row/recordset from table 1 to table 3. I can read an entire row/recordset ...
0
by: beebelbrox | last post by:
Hi, I am new VB programming in Access and I am requesting help with the following code. This code is attached to a form that will display a specific recordset based in information passed to the...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
5
by: trixb | last post by:
Hello all, Here is what I need to do and need help with: I have a table that is feeding a chart in a report in Access. If this table has more than 50 records, the graph gets messy, and this is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.