Reverse engineering an event
From: benb (anonymous_at_discussions.microsoft.com)
Date: 05/13/04
- Next message: Alex Dybenko: "Re: Reverse engineering an event"
- Previous message: JR: "Using code to create a table"
- Next in thread: Alex Dybenko: "Re: Reverse engineering an event"
- Reply: Alex Dybenko: "Re: Reverse engineering an event"
- Reply: Derrick: "Reverse engineering an event"
- Reply: John Vinson: "Re: Reverse engineering an event"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 13 May 2004 09:41:21 -0700
I am trying to reverse engineer an On Click event for a control in an Access form. Here is what I am trying to do:
There is a field in which the user will enter the name of a contact (s)he wants to find in the database. Below it is a control which the user will click to look for that contact. On Click I want Access to use the criteria entered into the field to modify the criteria in a query linked to a form and run that form to display all the possible matches. I know it can be done because someone else did it in an older database that we do not use anymore. I am getting a compile error that says "User-defined type not defined" Here is the script that was used:
Option Compare Database
Option Explicit
Sub BuildSQLString(strSQL As String)
Dim strWhere As String
If Not IsNull(txtName) Then
strWhere = strWhere & " AND Name LIKE" & "'*" & txtName & "*'"
End If
If Len(strWhere) > 0 Then strSQL = Mid$(strWhere, 6)
End Sub
Private Sub Run_Click()
If IsNull(txtName) Then MsgBox "You gotta enter a name!"
On Error GoTo Exit_Run_Click
Dim strWhere As String
Dim qdf As QueryDef <------THE DEBUGGER SELECTS THIS SCRIPT AFTER THE COMPILE ERROR
BuildSQLString strWhere
If ChangeQueryDef("qryContactookup", "select qryContactLookup1.* from qryContactLookup1 where " & strWhere) Then
End If
DoCmd.OpenForm "Form ViewContacts", acNormal
DoCmd.Close acForm, "Form ContactLookup", acSaveNo
Exit_Run_Click:
Exit Sub
End Sub
Private Function ChangeQueryDef(strQuery As String, strSQL As String)
If strQuery = "" Or strSQL = "" Then Exit Function
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs(strQuery)
qdf.SQL = strSQL
qdf.Close
RefreshDatabaseWindow
ChangeQueryDef = True
End Function
Private Sub Cancel_Click()
On Error GoTo Err_Cancel_Click
DoCmd.Close
Exit_Cancel_Click:
Exit Sub
Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click
End Sub
The truth is that I am a beginning VB user so I may be biting off more than I can chew, but any help would be appreciated. How should I define the user-defined type?
- Next message: Alex Dybenko: "Re: Reverse engineering an event"
- Previous message: JR: "Using code to create a table"
- Next in thread: Alex Dybenko: "Re: Reverse engineering an event"
- Reply: Alex Dybenko: "Re: Reverse engineering an event"
- Reply: Derrick: "Reverse engineering an event"
- Reply: John Vinson: "Re: Reverse engineering an event"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|