-
WSlesoch
AskWoody LoungerAugust 2, 2002 at 2:30 am in reply to: Results correct only on stepping in the codes (A2K SR1) #605565The solution you suggested worked very well. Thanks. Well, I have to be sure that what showed well while in debugging session worked the same while out of debug mode.
-
WSlesoch
AskWoody LoungerThanks for your prompt and thorough reply. I use method(1) to catch the error. Method (2) didn’t work as it didn’t catch the error – it didn’t catch error due to null value for a required field. Method(3) works for my combo boxes.
-
WSlesoch
AskWoody LoungerThanks for your explanation, HansV. My tables contains only about 1000 rows and it is rather small. I experimnted with it and couldn’t visibly find the difference. That’s why I seek help. Thanks again, and to Charlotte too.
-
WSlesoch
AskWoody LoungerSorry for the errors in the Sub that I sent. It is mainly due to my shoddy attempt to edit out irrelevant portion of the codes and renaming some of the variables. I re-post my problem as follows:
I have a main form frmMain which displays all the records in my main table (the RecordSourec). I have a command button in frmMain called cmdSearch which would open up a form frmSearch where users key in search data (one of them is txtName for the field Name) for the various fields to search for the desired records. When a user press the command button cmdAccept in frmSearch, frmSearch would be closed and the searched results would be displayed in frmMain.
The Sub Accept for cmdAccept is as follows (both the detailed SQL statement (to search for other fields) and the error trapping are left out for simplicity):
Private Sub Accept()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As StringstrSQL = “SELECT * FROM tblData WHERE Name LIKE ‘” & txtName & “*'”
strSQL = strSQL & ” ORDER BY Name;”Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)If rst.BOF And rst.EOF Then
MsgBox “There is no record.”
rst.Close
Set rst = Nothing
DoCmd.Close
Exit Sub
End If‘ Populate the recordset else only the first record will be displayed
rst.MoveLast
rst.MoveFirst
DoCmd.Close
Set Forms(“frmMain”).Recordset = rst
‘ The rst isn’t closed
Set rst = Nothing
Set db = NothingEnd Sub
The codes work except that I need to insert
rst.MoveLast
rst.MoveFirst
before I close the form.I followed your advice as I understand it and re-code the Sub as below (let me call it Accept1:
Private Sub Accept1()
Dim strSQL As String
strSQL = “SELECT * FROM tblData WHERE Name LIKE ‘” & txtName & “*'”
‘ Close frmSearch
DoCmd.Close
Forms(“frmMain”).RecordSource = strSQLEnd Sub
When I ran the program, my frmMain showed only a single empty record. Did I understand your correctly, Charlotte? Where did I go wrong?
-
WSlesoch
AskWoody LoungerHere is the codes, Charlotte:
Private Sub cmdOK()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As StringOn Error GoTo TanganiErr
‘ txtName is a textbox for user’s input in frmInfo
strSQL = “SELECT * FROM tblData WHERE Name LIKE ‘” & txtName & “*'”
End IfSet db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)
rst.MoveLast
rst.MoveFirst‘ frmInfo is the calling form in which txtName is found
Set Forms(“frmInfo”).Recordset = rst
Set rst = Nothing
Set db = NothingEnd Sub
-
WSlesoch
AskWoody LoungerThanks Gray & Dave for your help.
I did a debug.print to list out the names after executing the SQL command, all the names starting with “L” were printed, implying the SQL statement was okay. After debug,print, the form displays correctly too all the records required. If I comment out the debug. print statement, it was back to single record.
Then I added rst.MoveLast and rst.MoveFirst after running the SQL, the form displays correctly all records with names that start with “L”.
The reason(s), anyone?
-
WSlesoch
AskWoody LoungerJuly 23, 2002 at 6:59 am in reply to: DAO form cannot be updated after printing report (A2K SR1) #1794375When I read your reply, Charlotte, it immedately hit me that you had gotten to the root of the problem! My Print command button prints the current record (record on display), and I used SQL to narrow it down to a single record before sending it to the report. I re-issued the SQL after I hit the Print button, and everything is back to normal. Thanks a lot, Charlotte. Why it had never dawned on me that I had filtered the table down to a single record?
BTW, is there a simple method with DoCmd that I can use to print the current record without resorting to SQL?
I was a little hesitant to send my sub over because all my user’s variable anmes, sub names, messages etc were written using the local native language, or a combination of English and the native language, and they may appear odd to you without editing. I will send one over next time if there is a necessity. Thanks.
-
WSlesoch
AskWoody LoungerYes, I can compact my database using the Access’s Database Utilities, but what if I want to do the same in codes within the database, say as an option in the user’s switchboard or user’s menu, without the benefit of the Database Utilities in the Access’s menu?
-
WSlesoch
AskWoody LoungerI am under the impression that autonumber once given, is given, even if a record with that autonumber is removed, leaving gap in the autonumbering. I do use autonumber in my database. If I have a 100 records with the same sequential autonumber, and I removed record number 50 (also autonumber 50), the autonumber 50 will not be issued again. Or does it affect only the highest autonumber, meaning the 100th reord? If I remove record with autonumber 100, compact the database, then the first new record wii have autonumber 100. Is it what you said?
If I use autonumber as my row ID, but keep the records marked with deletion in the same table as the main one, then there will not be any problem?
-
WSlesoch
AskWoody LoungerJuly 22, 2002 at 7:51 am in reply to: DAO form cannot be updated after printing report (A2K SR1) #1794370The other command buttons on the form are navigation buttons, Search, and Close buttons (containing plain DoCmd.Close). They failed to respond after printing but were responding as expected if the Print button wasn’t executed. I can display my listbox and combobox on the form, but I can’t update the fields. I can’t change the values in my textboxes. Have I done anything wrong?
-
WSlesoch
AskWoody LoungerThanks, Charlotte. I am a long-time user of MS Windows but just beginning to program in it. I am glad I shift to writing database program in Windows and changing my habit and mindset which was orientated to DOS platform along the way. I know more about intricacies about Windows programming. Another reason for me to move to Windows platform has to do with printers – more and more new printers provide no drivers for DOS printing!
-
WSlesoch
AskWoody LoungerSorry, MarkD, neither do I know who is David:) I got mixed up along the way. My sincere apology and thanks for your help.
-
WSlesoch
AskWoody LoungerThanks, David. It works.
-
WSlesoch
AskWoody LoungerNo, Charlotte, the items in the two listboxes are independent of each other, though they are under the same broad category. DavidD’s advice worked very well for me. Thanks.
-
WSlesoch
AskWoody LoungerThanks Charlotte, your solution works like a charm.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Get back ” Open With” in context menus
by
CWBillow
1 hour, 4 minutes ago -
Many AMD Ryzen 9800X3D on ASRock have died
by
Alex5723
2 hours, 1 minute ago -
simple general stupid question
by
WSaltamirano
5 hours, 41 minutes ago -
Automatic Toggle code for pages and bookmarks for Table of Content (Awaiting moderation)
by
switchtolinux
6 hours, 23 minutes ago -
April 2025 Office non-Security updates
by
PKCano
13 hours, 4 minutes ago -
Microsoft wants to hear from you
by
Will Fastie
14 hours, 15 minutes ago -
Windows 11 Insider Preview Build 22635.5160 (23H2) released to BETA
by
joep517
16 hours, 36 minutes ago -
Europe Seeks Alternatives to U.S. Cloud Providers
by
Alex5723
22 hours, 7 minutes ago -
Test post
by
Susan Bradley
1 day ago -
Used Systems to delete Temp files Gone WRONG what does this mean?
by
Deo
1 day, 2 hours ago -
SSD shuts down on its own
by
CWBillow
17 hours, 26 minutes ago -
OneDrive File Sharing Changes
by
David Clark
1 day, 10 hours ago -
OneDrive File Sharing Changes
by
David Clark
1 day, 12 hours ago -
Win 10 Pro 22H2 to Win 11 Pro 23H2 Conversion Guide
by
doneager
12 hours, 13 minutes ago -
Today is world backup day
by
Alex5723
1 day, 3 hours ago -
Windows .exe on Mint
by
Slowpoke47
1 day, 13 hours ago -
Reviewing your licensing options
by
Susan Bradley
23 hours, 27 minutes ago -
Apple has been analyzing your photos since September 2024
by
B. Livingston
8 hours, 59 minutes ago -
What Windows 11 24H2 offers beyond bugs
by
Lance Whitney
4 hours, 50 minutes ago -
Making sense of Settings in Windows 11
by
Simon Bisson
6 hours, 10 minutes ago -
Windows 11 pro fails to log in after upgrading Win 10 pro to Win 11 pro 24h2
by
ben_sitaud
1 day, 9 hours ago -
23H2 / 24H2 / Local v. Microsoft Account.
by
CWBillow
1 day, 7 hours ago -
YouTube Ad Blocker Blocker
by
bbearren
1 day, 7 hours ago -
Obscure historical facts about Windows
by
Cybertooth
1 day, 9 hours ago -
Microsoft Backup
by
Linda2019
1 day, 1 hour ago -
What is the best notepad++ version for W7?
by
Picky
1 day, 8 hours ago -
What are right steps to move MS 365 Office+OneDrive files from PC to iMac?
by
glnz
2 days, 18 hours ago -
How to move existing MS 365 Office with OneDrive files from PC to new iMac
by
glnz
2 days, 18 hours ago -
How to move MS 365 files (some on OneDrive) from PC to iMac
by
glnz
3 days, 13 hours ago -
Microsoft adding Quick Machine Recovery to Windows 11
by
Alex5723
3 days, 13 hours ago
Recent blog posts
Key Links
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.