-
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.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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
-
MS Passkey
by
pmruzicka
2 hours, 16 minutes ago -
Can’t make Opera my default browser
by
bmeacham
4 hours, 10 minutes ago -
*Some settings are managed by your organization
by
rlowe44
2 hours, 3 minutes ago -
Formatting of “Forward”ed e-mails
by
Scott Mills
3 hours, 4 minutes ago -
SmartSwitch PC Updates will only be supported through the MS Store Going Forward
by
PL1
22 hours, 46 minutes ago -
CISA warns of hackers targeting critical oil infrastructure
by
Nibbled To Death By Ducks
1 day, 7 hours ago -
AI slop
by
Susan Bradley
1 day, 6 hours ago -
Chrome : Using AI with Enhanced Protection mode
by
Alex5723
1 day, 9 hours ago -
Two blank icons
by
CR2
18 hours, 37 minutes ago -
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
1 day, 17 hours ago -
End of 10
by
Alex5723
1 day, 20 hours ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
18 hours, 32 minutes ago -
test post
by
gtd12345
2 days, 2 hours ago -
Privacy and the Real ID
by
Susan Bradley
1 day, 16 hours ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
1 day, 8 hours ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
2 days, 7 hours ago -
Upgrading from Win 10
by
WSjcgc50
18 hours, 42 minutes ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
22 hours, 16 minutes ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
2 days, 22 hours ago -
The story of Windows Longhorn
by
Cybertooth
2 days, 10 hours ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
3 days ago -
Are manuals extinct?
by
Susan Bradley
59 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
3 days, 9 hours ago -
Network Issue
by
Casey H
2 days, 20 hours ago -
Fedora Linux is now an official WSL distro
by
Alex5723
3 days, 21 hours ago -
May 2025 Office non-Security updates
by
PKCano
3 days, 22 hours ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
4 days ago -
pages print on restart (Win 11 23H2)
by
cyraxote
3 days ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
4 days, 2 hours ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
4 days, 2 hours ago
Recent blog posts
Key Links
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.