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

Form navigation buttons do not show correct position

Hello
I have a form to enter names and some other personal information.
When a name is entered, it is checked against existing records: maybe,
such name was entered before? If yes, user is notified and asked, would
you like to see the previous record? If user answers yes, form on the
screen is scrolled to the record with the same name. All works well,
apart from number of record between navigation buttons: it is still the
same number of the last added record! This is very misleading. I need
the correct number of record.

Interesting that despite being shown as for example "30 of 30", if to
click Go To Last button, the form returns to the last record and
navigation buttons still show "30 of 30", in this case correctly.

A code, which processes the search is:

Private Sub Form_AfterUpdate()
Dim rst As DAO.Recordset, strStudent As String, Resp
Set rst = Forms!frmStudents.RecordsetClone
With rst
strStudent = "[Student Name] = '" & Me![Student Name] & "' AND
SURNAME='" & Me![Surname] & "'"
rst.FindFirst strStudent
If rst.NoMatch Then
Else
Resp = MsgBox("There is a student with the same name. Would you
like to see?", vbYesNo, "CON Faculty waiting lists")
If Resp = vbYes Then
Call FindStudent(Me![Student Name], Me!Surname)
End If
End If
End With
Set rst = Nothing
End Sub

Public Sub FindStudent(StudentName As String, Surname As String,
Optional Age As Integer)
Dim rst As DAO.Recordset, strStudent As String, F As Form
Set F = Forms("frmStudents")
Set rst = F.RecordsetClone
With rst
rst.MoveFirst
strStudent = "[Student Name] = '" & StudentName & "' AND SURNAME='" &
Surname & "'"
If Not IsMissing(Age) And Age <> 0 Then strStudent = strStudent & " AND
AGE=" & Age
rst.FindFirst strStudent
If rst.NoMatch Then
MsgBox "There is no such student.", vbOKOnly, "CON Faculty waiting
lists"
Else
F.Bookmark = rst.Bookmark
End If
'End If
End With
Set rst = Nothing
End Sub

Any help will be greatly appreciated.
Galka

Dec 14 '05 #1
1 2525
I see a couple of problems.

1) In the line where you assign the Surname as criteria, you are using
apostrophes (single quotes) as the text delimiter. This will work until you
run across a name that has an apostrophe in it, such as O'Hare. If you
double up the double quotes, that'll tell VBA that you want the double quote
as part of the string instead of as a delimiter. Replace each apostrophe
with 2 double quotes and that'll take care of the problem. You're probably
safe on the first name, but you could do the same thing there also if you
want to.

Example:
strStudent = "[Student Name] = '" & Me![Student Name] & "' AND SURNAME=""" &
Me![Surname] & """"

2) In your search, you're searching for FindFirst. This will give you the
first match found. The new entry has already been saved to the table, so is
available to be found. In fact, since you're making the original check in
the form's AfterUpdate event, I would suspect you'll always find a match.
The AfterUpdate event fires after the record has been saved, so when doing a
FindFirst, you'll always find at least the record you just entered.

This would normally be handled in the form's BeforeUpdate event. It would be
used to allow you to abort the current record and go to the other one. Even
better, you may want to make this check as soon as both the first name and
last name textboxes are filled in. This would save the user from filling in
a whole record, just to find that one already exists. Advise the user that
if they fill in the record by filling in the first and last names first,
that they may not have to complete the record if one already exists. Most
folks, not wanting to waste their time, will make sure they fill in the name
fields first. These two fields should also be 0 and 1 in your tab order. If
the users chooses to fill in the fields in a different order, the check will
still happen when these two fields are completed, they've just wasted their
time filling in the other fields if it wasn't needed.

--
Wayne Morgan
MS Access MVP
"Galka" <ga****@mail.ru> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hello
I have a form to enter names and some other personal information.
When a name is entered, it is checked against existing records: maybe,
such name was entered before? If yes, user is notified and asked, would
you like to see the previous record? If user answers yes, form on the
screen is scrolled to the record with the same name. All works well,
apart from number of record between navigation buttons: it is still the
same number of the last added record! This is very misleading. I need
the correct number of record.

Interesting that despite being shown as for example "30 of 30", if to
click Go To Last button, the form returns to the last record and
navigation buttons still show "30 of 30", in this case correctly.

A code, which processes the search is:

Private Sub Form_AfterUpdate()
Dim rst As DAO.Recordset, strStudent As String, Resp
Set rst = Forms!frmStudents.RecordsetClone
With rst
strStudent = "[Student Name] = '" & Me![Student Name] & "' AND
SURNAME='" & Me![Surname] & "'"
rst.FindFirst strStudent
If rst.NoMatch Then
Else
Resp = MsgBox("There is a student with the same name. Would you
like to see?", vbYesNo, "CON Faculty waiting lists")
If Resp = vbYes Then
Call FindStudent(Me![Student Name], Me!Surname)
End If
End If
End With
Set rst = Nothing
End Sub

Public Sub FindStudent(StudentName As String, Surname As String,
Optional Age As Integer)
Dim rst As DAO.Recordset, strStudent As String, F As Form
Set F = Forms("frmStudents")
Set rst = F.RecordsetClone
With rst
rst.MoveFirst
strStudent = "[Student Name] = '" & StudentName & "' AND SURNAME='" &
Surname & "'"
If Not IsMissing(Age) And Age <> 0 Then strStudent = strStudent & " AND
AGE=" & Age
rst.FindFirst strStudent
If rst.NoMatch Then
MsgBox "There is no such student.", vbOKOnly, "CON Faculty waiting
lists"
Else
F.Bookmark = rst.Bookmark
End If
'End If
End With
Set rst = Nothing
End Sub

Any help will be greatly appreciated.
Galka

Dec 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Picho | last post by:
Hi all, Is there any .NET way (I am not rulling out API usage) to add button(s) to a form's title bar? I found some non-.NET solutions that did actually work in VB6 but not in the ..NET...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
18
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead....
3
by: Jack Russell | last post by:
I want to add navigation buttons to a tabcontrol (somewhat like excel) How do I get the "tabs" to offset to the right so that I can draw the buttons on the left? TIA -- Remove norubbish to...
3
by: zhouzhendong | last post by:
I have a form that shows a table in single form format. how can I know the position of the record the form is current showing so that I can enable or disable some buttons according to the position...
1
by: erick-flores | last post by:
Hello all quick question, how do I make my form to not show the record navigation at the botton/left of the form. I just want to use my form for input data, but i dont want to see that...
1
by: grabit | last post by:
Hi Peoples i have a search page with a form field "subject" on my results page i have a paging routine . the first page lists its 10 records no trouble but when i click the "next" link i get a error...
2
tharden3
by: tharden3 | last post by:
I have a question for you guys, I'm designing a website. Before I go any further, I'd like to get my navigation bars on the left side up and running. The site is themed to a bumblebee 'black and...
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?
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.