Reverse engineering an event

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Derrick (anonymous_at_discussions.microsoft.com)
Date: 05/13/04


Date: Thu, 13 May 2004 10:44:35 -0700

Here's a sample.

This form is used to build the recordsource for another
form.

'Place a global variable in a module
Public gblName as String

'Prompt the user with a form
If Me.txtLookUpName.Value <> "" Then
     gblName = Trim(txtLookUpName)
     DoCmd.OpenForm "frmFormName", acNormal
     DoCmd.Close acForm, Me.Form.Name
Else
     MsgBox "You need to provide a name."
End If

'Set the recordsource when the frmFormName loads
Me.Form.RecordSource = "SELECT * FROM TableName WHERE
FieldName= '" & gblName & "';"
Me.Form.Requery

'If you open up the form that prompt for Name you can do
someting like this.

If Me.txtLookUpName.Value <> "" Then
    gblName = Trim(txtLookUpName)
    Forms![frmFormName].RecordSource = "SELECT * FROM
TableName WHERE FieldName= '" & gblName & "';"
                        
    Forms![frmFormName].Requery
    DoCmd.Close acForm, Me.Form.Name
Else
    MsgBox "You need to provide a name."
End If

Good Luck

>-----Original Message-----
>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?
>.
>



Relevant Pages

  • Project Error
    ... Private Declare Sub Sleep Lib "Kernel32" ... Dim strDataSrc As String ...
    (microsoft.public.vb.bugs)
  • Re: dMax
    ... immediate window but nothing is happening when I enter data into the form. ... >>> Dim strWhere As String ... >>> End Sub ...
    (microsoft.public.access.forms)
  • Re: FTP CD command
    ... Private _Uri As String ... Public Sub New(ByVal Uri As String, ... Dim listRequest As FtpWebRequest = CType, ... Public Sub UploadAsynch(ByVal fileName As String, ByVal uploadUrl As ...
    (microsoft.public.dotnet.languages.vb)
  • RE: jpgs not showing on forms
    ... Rather than embed the pictures in the database store the paths to the JPEG ... Private Sub cmdAddImage_Click ... Dim strAdditionalTypes As String, strFileList As String ... Private Sub cmdDeleteImage_Click ...
    (microsoft.public.access.gettingstarted)
  • Re: FTP CD command
    ... My code connects to a ftp site and the enumerates all content on that place ... Public Property UriAs String ... End Sub ... Dim listRequest As FtpWebRequest = CType, ...
    (microsoft.public.dotnet.languages.vb)