Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...If I'd only had resource like eng-tips when I was just getting started! I might have dazzled them with my brilliance instead of my BS..."

Geography

Where in the world do Tek-Tips members come from?
hwmueller (TechnicalUser)
23 Jan 01 5:57
Hi

I have a query that when run asks for the user to enter the name of the staff member whose details are required. When entered correctly the query runs fine. When no name or a wrong name is entered the query just produces a blank screen. I wish to change that so a message appears stating either "Please enter a name" or "That name is spelt incorrectly or doesn't exist". How do I do this??

Thanks

Hans
braindead2 (TechnicalUser)
23 Jan 01 15:27
Test to see if there is a match first
something like!!!
dim rst as recordset,db as database,strsql as string
strsql = "select name from yourquery where name = '" & yourfieldname & "'"
set db= Currentdb
set rst = db.openrecordset (strsql)
if rst.recordcount <1 then
msgbox " No records found Please Reenter Name"
 
else
docmd.openquery "Yourqueryname"
end if
rst.close
hwmueller (TechnicalUser)
24 Jan 01 9:26
thanks. I have some further questions about the above.

What is the Private Subs name that should be used?
Is the above module entered in under the form corresponding to the query? If not where then?

Thanks
hwmueller (TechnicalUser)
24 Jan 01 11:03
Hi

After much trying and little success I have now written below exactly how my query looks:

COLUMN 1

FIELD: Staff details*
TABLE: Staff details

COLUMN 2

FIELD: Surname
TABLE: Staff details
CRITERIA: [Enter Staff Member's Name]

In the properties the recordset type is on Dynaset.

So, where do I enter the code written above and how do I link it to this query? At the moment I have entered the code in the corresponding form window. When I run it without entereing a name or using a wrong one, all I get is a blank screen

Thanks
braindead2 (TechnicalUser)
24 Jan 01 14:11
I apologize I assumed you were launching the query from a form. I do not know of a way to make what you want just using SQL.
I would suggest that you consider using a form.

create a unbound form (no source)
on the tools menu create a combobox make sure the wizard button (the wand with the stars) is pressed when you select the combo box.
place the combo box on the form. when the wizard opens.
Select look up the values in a table or query
select staffdetails table as the source
select surname as the field
adjust the field width then hit finish
right click on the new combo box and open the properties window. name the combo "Namesearch" then be sure the limit to list property is set to yes.
This combo box will now ony show surnames of those that are avaliable, ensuring the query will return data.
Now save the form as "Search form"
open your query and in the criteria type
Forms![Search Form]![Namesearch].
save the query as "surnamesearchQRY"
now open your from in design mode and go back to the combo boxes properties.
In the after update event click the 3 dots to the right and select code
this will open the code window
place this code in between where it says
Private Namesearch_afterupdate() and End sub
docmd.openquery "surnamesearchQRY"
now open the from type or select a surname hit the enter key and the query will pop up
hwmueller (TechnicalUser)
29 Jan 01 10:16
Hi

Thanks very much for this. I have tried it but think that I am still doing something wrong. Essentially what I want is that when selected in the switchboard, a question pops up which says "Enter Staff Members Name". If this corresponds with an actual name, then a form opens with the details corresponding to that name. If no such name exists, a second pop up should appear which say so. Is this possible??

Thanks

Hans

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close