Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2004, 09:06 PM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create Search Button on Access Form

Hello.

I am creating an Access 2000 database to keep track of employee's Ergonomic Information and their related Cubicle Information. The database has five tables:
tbl_Cubicle_Info
tbl_Emp_Data
tbl_Ergo_Info
tbl_Keyboard
tbl_Pointing_Device

I want ot be able to enter either an Employee Number, First Name, or Last Name on a form and click on a "Search Button" and have the related Ergonomic Info and the Cubicle Info displayed on two seperate subforms.

I have seen this in an Access 2 database. I tried coping the code into my database but some of the code isn't recognized by 2000.

Here is the code:

Private Sub cmdSearch_Click()
On Error GoTo cmdSearchErrorTrap
Dim MySQL As String, MyCriteria As String, MyRecordSource As String
Dim ArgCount As Integer
Dim Tmp As Variant
ArgCount = 0
MySQL = "Select * from [Employee Data] where "
MyCriteria = ""
AddToWhere [Last Name], "[Last Name]", MyCriteria, ArgCount
AddToWhere [First Name], "[First Name]", MyCriteria, ArgCount
AddToWhere [Employee Number], "[Employee Number]", MyCriteria, ArgCount
AddToWhere [User ID], "[User ID]", MyCriteria, ArgCount
AddToWhere [Phone ID], "[Phone ID]", MyCriteria, ArgCount
AddToWhere [Initials], "[Initials]", MyCriteria, ArgCount
If MyCriteria = "" Then
MyCriteria = "True"
End If
MyRecordSource = MySQL & MyCriteria
Me!frmEmpInf.Form.RecordSource = MyRecordSource
If Me!frmEmpInf.Form.RecordsetClone.RecordCount = 0 Then
MsgBox "No records match the criteria you entered.", 48, "No Records Found"
Me!cmdClear.SetFocus
Else
'Tmp = EnableControls("Detail", True)
Me!frmEmpInf.SetFocus
End If
cmdSearchResume:
Exit Sub
cmdSearchErrorTrap:
MsgBox Error$
Resume cmdSearchResume
End Sub

The error

Compile error:
Sub or Function not defined

comes in at the first AddToWhere line. I noticed that for his database he has all of the data coming from one table.

I have little to no experience with VB or VBA. Is there a way to make this work without having to consolidate all of my data into one table?
 
Old February 27th, 2004, 09:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by BKILBAN
 The error

Compile error:
Sub or Function not defined

comes in at the first AddToWhere line. I noticed that for his database he has all of the data coming from one table.
The Sub "AddtoWhere" is not an Access pre-defined sub. It's a user-defined sub that someone programmed to work with the code you listed. You cut and pasted your code into your form, but you forgot to ALSO cut and past the Sub AddtoWhere into your code, too.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create User Search Form JezLisle Access 1 November 6th, 2008 11:22 AM
Search button doesn't search Access DB cbones Visual Studio 2008 1 October 27th, 2008 07:36 PM
search button ct Excel VBA 0 April 11th, 2006 09:50 AM
Create/Add controls to Access Form: VBA program AccessBeginner Access VBA 1 October 13th, 2005 06:48 AM
asp code for search button ct ASP.NET 1.0 and 1.1 Basics 2 August 25th, 2005 03:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.