Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Null Search Creating a New Rec
Dg Ewing 
     
4 years ago
I have a multi field search on my form.  And if the search cannot find any records meeting criteria, it returns the empty form with "new" in the autonum key field.  But if I esc, or click show all, or the refresh btn, a new empty record is created.

this is my code:

Private Sub command555_Click()

    Dim strsearch2 As String
    Dim strText2 As String
    strText2 = Me.TxtSearch.Value
    strsearch2 = "SELECT * from A_MemberT where  ((MemName like ""*" & strText2 & "*"")or (MemMstrID like ""*" & strText2 & "*"")or (Group like ""*" & strText2 & "*"")or (MemIDer like ""*" & strText2 & "*"") or (email like ""*" & strText2 & "*"")or ([Managedby] like ""*" & strText2 & "*"") or (MemID like ""*" & strText2 & "*"")) "
    Me.RecordSource = strsearch2
End Sub
Dg Ewing OP  @Reply  
     
4 years ago

Dg Ewing OP  @Reply  
     
4 years ago
btw, I would love to break up the very long line, by adding _ & ( or what ever """" ' ' '"" ,quotes, double/double, single/double) so that the strsearch2 line is easy to read.....I have tried several times, and have watched the double/double double/trouble quote video too many times.....it still hurts my head....I think it is some sort of Kobayashi Maru Test created by a sick person at MS!
Dg Ewing OP  @Reply  
     
4 years ago
How can I eliminate creating a new record?  thanks
Alex Hedley  @Reply  
           
4 years ago
Are you setting a field as the default field?
Are you clicking into a field?
Do you have any fields with Default Values?
Does the > turn to a ✏️ ? i.e. is the record dirty?
Dg Ewing OP  @Reply  
     
4 years ago
Alex , thank you!!

Just your questions lead me instantly to my problem.  

Way back when, I had code to kick in on "get focus" of the prim key to set a "default" value based on incongruent criteria (not a constant), and that and that was causing the key field to update causing a new record to be generated.

I had subsequently rewrote the code to set the default after the MemName was "updated" as it would always have data, and never removed the "on focus"

all is well, except that I still can not get my line breaks in my code to work
Scott Axton  @Reply  
        
4 years ago
Go watch the Convert Query SQL to VBA video.
Not only does Richard explain how to split out your SQL but you create a little tool to automatically do so.

Be sure to read the Comments below that video.  There are a couple of little errors that were caught afterward but the tool works great!
Dg Ewing OP  @Reply  
     
4 years ago
Thanks Scott, that is an awesome vid..I have watched it several times, including the extra.  I have watched the double double damn I am in trouble too many times....

It has not clicked and I think that I have zoned out...It will never click.  Unfortunately I created the code "by hand" so it is not in query SQL form , it is already in VBA form and the converter adds 6,000 """"" all over the place.

I am hoping that some one can just provide a sub for the bbbb and the cccc.  this one line works fine when it is one line, but when I put :

a line feed at the bbbb  and
tabs  at the cccc

the VBA goes to hell in a hand basket.

Dg Ewing OP  @Reply  
     
4 years ago
"SELECT * from A_MemberT where  ((MemName like ""*" & strText2 & "*"") bbbb
ccccor (MemMstrID like ""*" & strText2 & "*"") bbbb
ccccor (Group like ""*" & strText2 & "*"") bbbb
ccccor (MemIDer like ""*" & strText2 & "*"") bbbb
ccccor (email like ""*" & strText2 & "*"") bbbb
ccccor ([Managedby] like ""*" & strText2 & "*"") bbbb
ccccor (MemID like ""*" & strText2 & "*"")) "
Scott Axton  @Reply  
        
4 years ago
Put your SQL into a variable.  Then use MsgBox to make sure it gets concatenated correctly.
     S = SELECT blah blah all on one line. (You said that works - correct?)
     MsgBox S
Run it

Now put in one line continuation - forget about the tab for the moment.  When you do that you have to close the quote for the first line and add the & _
Like this:  
    S = "SELECT * from A_MemberT where  ((MemName like ""*" & strText2 & "*"") " & _
or (MemMstrID like ""*" & strText2 & "*"") blah blah <- This will turn RED

Now since you started a new line you have to open your quote again right before the or   "or (MemMstrID like ""*" & strText2 & "*"") <-The rest of the line should turn black.

To test it do a MsgBox S to make sure it runs.    

Just do one at a time. Testing as you go.  It is a pain but you will eventually see the pattern in what you are doing.  Once you do about a kabillion times it will sink in.  There really isn't a magic bullet.  You just have to do it.
Scott Axton  @Reply  
        
4 years ago
Once you have the line broken out like you want you can go add in your tabs to move it over and make it look pretty.
Access doesn't care about that.  It DOES matter on SPACE characters for your SQL within the quotes.
Dg Ewing OP  @Reply  
     
4 years ago
Thanks Scott,

That was easy just  add:        " & _
and on next line:                   "

Now I no longer have to use my double screen to review the code....wowzer

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 7:43:22 PM. PLT: 0s