[mso] Re: Access VB code needed

  • From: "Colli, Anthony G" <Anthony.Colli@xxxxxxx>
  • To: "'mso@xxxxxxxxxxxxx'" <mso@xxxxxxxxxxxxx>
  • Date: Fri, 3 Jan 2003 14:00:08 -0500

There are a couple ways to have forms pass parameters. The DoCmd.OpenForm
object has a parameter 'OpenArgs' that is sent to the form that is being
opened. It's usually used like: 

DoCmd.OpenForm "frmVTE_Diagnosis", acNormal, , , , , Nz(Me.txtPatientID, 0) 

Where Nz(Me.txtPatientID, 0) is the argument that is passed to the form that
is being opened. In the Onload even of the form being opened you can check
for these 'OpenArgs' and do what ever you need to with them. like this:
(From the load event of "frmVTE_Diagnosis")

--------------------------------------------------
Private Sub Form_Load()

Dim strResult As Variant

On Error GoTo MyMistake

    If IsNull(Me.OpenArgs) Then
        MsgBox "Select a value First"
        DoCmd.Close acForm, Me.Name
        GoTo ExitSub
    End If

    strResult = 0
    strResult = Nz(DLookup("[PatientID]", "VTE_Diagnosis", "[PatientID] = '"
& Me.OpenArgs & "'"), 0)

    If strResult = 0 Then
          'Create the record
        MsgBox "Creating New Record For " & Me.OpenArgs, vbInformation,
"GCAT Information"
        DoCmd.GoToRecord , , acNewRec
        Me.txtPatientID.SetFocus
        Me.txtPatientID.Text = Me.OpenArgs

    Else
        'Find the record
        MsgBox "Searching for......" & Me.OpenArgs, vbInformation, "GCAT
Information"
        
        Dim rs As ADODB.Recordset
        Set rs = Me.RecordsetClone
        
        rs.Find "PatientID = '" & Me.OpenArgs & "'"
        
        Me.Bookmark = rs.Bookmark
        
        Set rs = Nothing
    
    End If
    
    Me.txtPatientID.SetFocus
    Me.txtPatientID.Locked = True
    DoCmd.Maximize
    
    Exit Sub
    
ExitSub:
    Exit Sub

    
MyMistake:
    MsgBox Err.Number & ", " & Err.Description, vbCritical, "Error"
    Resume ExitSub
    
End Sub
------------------------------------------------------------

Or you can have one form reference the value of a control on another form.
It usually works like this: 

me.txtCltID = Forms!frmClientinfo.txtCltID 

Where Forms! is the collection of forms in your database and
frmClientinfo.txtCltID refers to a control on that form. This generally
works pretty well but the form that is being referenced must be open or an
error will be raised. Use would use this from the onload event of the form
being open also. 

I just happen to be doing this very same thing. 

-Anthony






-----Original Message-----
From: April Pace [mailto:4office@xxxxxxxxxxxxx]
Sent: Friday, January 03, 2003 1:33 PM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Re: Access VB code needed



Ok this works great and I figured out how to get it to "popup" On now the
only problem is that it is not automatically populating the txtCltID which I
assumed that it would do like if I was using a subform in the form... So
What do I need to add to this code to populate the txtCltID field from the
original form (frmClientInfo) into this form that just popped Up?


Look Below... How close am I??

-----Original Message-----
if you click the build button (...) and go into VB then some code like this
might work. Where Check17 is the name of the checkbox and
"sfrmCltMailingaddy" is the name of the form you want to open.

Private Sub Check17_AfterUpdate()

    If Me.Check17.Value = True Then
                DoCmd.OpenForm "sfrmCltMailingadd"
                '[txtCltID].Form "frmClientinfo" = [txtCltID].Form
"sfrmCltMailingAdd"
    Else
                'do nothing
    End If

End Sub

-Anthony


*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx?Subject=unsubscribe

Or, visit the group's homepage and use the dropdown menu.  This will also
allow you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation
with instructions.  Once you are a member of the files group, you can go
here to upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************


*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx?Subject=unsubscribe

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: