473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Creating A Filter Dialog Box With An Unknown Value

Hello,

I am creating a dialog box that filters data on another form. Currently, i've added 2 text boxes (txtFirstName & txtLastName) & a command button that will open my form from the text inputed. This works well if you type "John" for the first name and "smith" for the last name. I want to be able to leave the first name blank (txtFirstName) and input a last name in txtLastName and be able show all of the people of the same last name on the form i open. In this example everyone with the same last name of "smith". I also want to be able to leave the last name empty and enter a first name.

Here is the event for the command button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2. On Error GoTo Err_Command15_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "SearchView"
  8.  
  9.     stLinkCriteria = "[LastName]=" & "'" & Me![txtLastName] & "'"
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  11.  
  12. Exit_Command15_Click:
  13.     Exit Sub
  14.  
  15. Err_Command15_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command15_Click
  18.  
  19. End Sub
can someone help?
Mar 5 '07 #1
5 2115
Rabbit
12,516 Expert Mod 8TB
Use an if/then/else statement to check for nulls and create the stLinkCriteria appropriately.
Mar 5 '07 #2
ADezii
8,834 Expert 8TB
Use an if/then/else statement to check for nulls and create the stLinkCriteria appropriately.
This should point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2. Dim stLinkCriteria As String
  3.  
  4. stDocName = "frmEmployees2"
  5.  
  6. 'Both First & Last Name missing
  7. If Len(Me![txtLastName]) = 0 And Len(Me![txtFirstName]) = 0 Then
  8.   Exit Sub
  9. 'First Name but no Last
  10. ElseIf Len(Me![txtFirstName]) > 0 And Len(Me![txtLastName]) = 0 Then
  11.   stLinkCriteria = "[FirstName]=" & "'" & Me![txtFirstName] & "'"
  12. 'Last Name but no First
  13. ElseIf Len(Me![txtFirstName]) = 0 And Len(Me![txtLastName]) > 0 Then
  14.   stLinkCriteria = "[LastName]=" & "'" & Me![txtLastName] & "'"
  15. 'Both First and Last Names
  16. Else
  17.   stLinkCriteria = "[FirstName]=" & "'" & Me![txtFirstName] & "' AND [LastName]=" & "'" & Me![txtLastName] & "'"
  18. End If
  19.  
  20. DoCmd.OpenForm stDocName, , , stLinkCriteria
Mar 5 '07 #3
I can see how the logic is put together, thanks.

but for sum reason it is running as before.

i'm supposed to put the whole if statement in the command button correct? i don't need to modify any other part of my data base?

thanks
Mar 5 '07 #4
Rabbit
12,516 Expert Mod 8TB
That would be correct. Did you make sure everything was named correctly? Since we don't know exactly how everything is named in your tables and forms, we can only guess at the ones we don't know.
Mar 5 '07 #5
that's what I thought, I'll triple check eveything. thanks again
Mar 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Eugen Walcher | last post by:
Hello All, I'm getting this error in my error_log in apache. Can anyone offer any assistance in fixing the problem? I'm using RH 9 with apache 2.0.53 and PHP v4.3.11
1
by: Keith | last post by:
A2003, Xp Pro. I've designed a form which contains 6 of combos. Three on the left are set up to select fields from a query, three on the right are set up to select values from the corresponding...
0
by: edwards_zim via AccessMonster.com | last post by:
I have a dialog box where I specify the criteria I would like to filter. What I would like to do is use this information to then print forms using this filter information without the form actually...
6
by: kaosyeti | last post by:
is there a way to create simple help file that i plan on linking to a command button on a form using what's already in access? i will probably be giving out this db that i've written to a number...
2
by: Leo | last post by:
I am using OPENFILENAME and GetSaveFileName to let user save a document out. However, the default name won't show up in the dialog and the selected filter can't be obtained (always got the default...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
3
by: Kim | last post by:
Im making a config file to a C# program in XML. I have save and load functions, but these require a base XML file with its structure to exsist (Im new to XML, so this was the way I it to work)....
1
by: stjulian | last post by:
I have a stored procedure which returns 2 tables and 1 output value. I want the first table to be assigned to rs1 and the second to rs2. However when I run this, I get the following error as I...
1
by: shank | last post by:
http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html I have the below code borrowed from above to open a "save as.." filedownload dialog box. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.