Search form, building complex SQL string with VBA (1 Viewer)

kloklo

Registered User.
Local time
Today, 17:38
Joined
May 27, 2013
Messages
21
But Media name works! If there is value in Me.txtMedijNaziv than strMedijNaziv is that value(exactly, or part of it). If I leave field blank than query shows all records.

For the rest of it...you gave me something to think about. I'm new to this VBA stuff, but really determined to learn it. Just, there is always more than one way to skin the cat, and I must learn not to mix things that doesn't belong together.

It will come with time and practice, right? :cool:

Many thanks, both to you and pr2-Eugene, for your time to teach me, and effort to correct my code.

You are great, guys! :)
 

JHB

Have been here a while
Local time
Today, 17:38
Joined
Jun 17, 2012
Messages
7,732
But Media name works! If there is value in Me.txtMedijNaziv than strMedijNaziv is that value(exactly, or part of it). If I leave field blank than query shows all records.
It was not a question if it works or not, it was a question WHEN the IF statement in the code becomes true?
It will NEVER, because first you add a value to the variable "strMedijNaziv" and afterwards you test it, to see if it is empty. :D :D
 

kloklo

Registered User.
Local time
Today, 17:38
Joined
May 27, 2013
Messages
21
Let's put it in simple words:

Simon says...let strMedijNaziv be whatever value written in txtMedijNaziv on the search form.
There is nothing written there?
Ok, in that case let strMedijNaziv be "Like '*'"

To answer your question, as I understand it, the IF statement becomes true if txtMediaNaziv is left blank.

Isn't Len function doing the same thing for those list boxes?

Or I have missed the barn and whole thing works just because I'm lucky? :D
 

kloklo

Registered User.
Local time
Today, 17:38
Joined
May 27, 2013
Messages
21
I just wanted to let you know...your code works beautiful!
All I had to add was one line to close output query before deleting it.

I can't thank you enough! My bags are packed...first really free vacation in ten years - here I come!

JHB, write me your physical adress in private message and I'll send you most beatufil postcard of Adriatic I can find. I mean it :)

That goes for you too, Eugene :)
 

pr2-eugin

Super Moderator
Local time
Today, 16:38
Joined
Nov 30, 2011
Messages
8,494
Sounds good.. :) Glad you have it all sorted..
JHB, write me your physical adress in private message and I'll send you most beatufil postcard of Adriatic I can find. I mean it :)

That goes for you too, Eugene :)
Thank you.. :)
 

JHB

Have been here a while
Local time
Today, 17:38
Joined
Jun 17, 2012
Messages
7,732
To answer your question, as I understand it, the IF statement becomes true if txtMediaNaziv is left blank.
Only for clarify things, (because the way you understand it, is NOT correct)! :)
Code:
 ' Build criteria string for Medij naziv
                 [B][COLOR=Red]strMedijNaziv[/COLOR][/B] = "LIKE '*" & Me.txtMedijNaziv.Value & "*'"
           If [B][COLOR=Red]strMedijNaziv[/COLOR][/B] = "" Then
           strMedijNaziv = "Like '*'"
          End If
If something is written in the txtMedijNaziv control, then strMedijNaziv=LIKE '*thevalueoftxtMedijNaziv*'
If nothing is written in the txtMedijNaziv control, then
strMedijNaziv=LIKE '**'
It will say strMedijNaziv will never be = ""
And your code test for strMedijNaziv=""
Or I have missed the barn and whole thing works just because I'm lucky? :D
Yes, sometimes you are just lucky. :D :D
Hope you'll have a relaxing holiday! :)
Originally Posted by kloklo
JHB, write me your physical adress in private message and I'll send you most beatufil postcard of Adriatic I can find. I mean it
I'll give you my address, but I think you already have left for vacation.

And at last, luck with you project in the future, glad to help you, (and I'm not such an old sour bastard as it might seem :D)!
 

Users who are viewing this thread

Top Bottom