Open form with where condition

Captive

New member
Local time
Today, 17:13
Joined
Apr 16, 2013
Messages
7
I try this code and it's not working

no record found

Code:
Private Sub openForm_but_Click()

   Dim whr As String

   whr = "get_date = #" & Me.gDate & "#"
   
   DoCmd.OpenForm "searchResult_form", acNormal, "", whr, acFormPropertySettings, acDialog

End Sub
 
What happens when you run it? Error Message? Form opens to non-matching Record? Nothing?

What version of Access are you using?

Possibilities:
  1. There is no matching Record
  2. You have a name spelled incorrectly: get_date, gDate or searchResult_form
  3. You have get_date and gDate backwards (i.e. in the wrong Forms)
Having taken the time to set up your scenario (as suggested by your code) with a number of matching Records in both Forms, and using your exact code, it worked flawlessly for me.

Linq ;0)>
 
I use Access 2007

When I run this code, No Error Message it just open blank form.
1. I'm sure there have matching Record.
2. I already check my spelling
3. get_date is fieldName and gDate is textBoxName

When I try to open Form by use another field (is not dateField) with this code
v
v
v
whr = "supply = " & Me.supp
DoCmd.OpenForm "searchResult_form", acNormal, "", whr, acFormPropertySettings, acDialog

It's work.
 
Last edited:
"" is a ZLS (zero-length-string) and it is not the same as Null. Get rid of it in the filter argument.
That was my first thought, too, Pat, but testing shows that it didn't matter, one way or the other!

Captive: Don't know what to tell you; as I said, I duplicated your scenario, used your exact code, and it worked like a charm! As most experienced developers will tell you, there are times when things that seem completely extraneous to the situation can cause problems. If you can Zip your file (removing any confidential data, if need be) and attach it, I'll be happy to take a look at it and see what else I can figure out.

Linq ;0)>
 
Once again, don't know what to tell you! I have no trouble running your file and getting the correct results! I suspect that when you're getting no Record you are simply keying in an incorrect date, which, to be honest, is easy enough to do, when you're dealing with dates like 3/12/1464 and 12/12/1471!

Also, I have to say that I've seen many examples of really bad names, before, but don't think I've ever one as ill-advised as a Table named 'Report!' Please change this!

Linq ;0)>
 
Thanks for your helping. ^.^

And for your advising, I think table name 'Report' is not good like you but I know when it's too late.

If I change it, I must fix nearly all of my code however I will remember and don't do it again.
 

Users who are viewing this thread

Back
Top Bottom