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 March 15th, 2006, 02:04 PM
Registered User
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transfer control value from a Form to Subform

Hello everyone...

I have a form that I want to copy selected field values to another form & subform.
I have no problem copying some field values to frmEndorsement... but I can't figure out how
to copy the other field values to the frmEndorsementSubform. I tried several ways but I'm still
on a dead end...

Here's the actual example...

I want to transfer some selected fields from "frmEncounter" to "frmEndorsement" & "frmEndorsementSubform"

In my frmEncounter, I have these fields...
mdsunit, patientID, lastname, firstname, pcp, & encountID ( EncountID is autonumber-PK)

In my frmEndorsement, I have...
patientID, lastname, firstname

& in my frmEndorsementSubform, I have...
pcp, msdunit, & encountID ( encountID is numeric-long integer )

There is a link master-child field between frmEndorsement & frmEndorsementSubform which is patientID.

and below is my code that I got from Ms. Candace Tripp...
Thanks in advance... Jim

Code:
Private Sub cmdcopy_Click()
On Error Resume Next    
Dim bOpen As Boolean    
Dim ctl As Control    
Dim frm2 As Form    
Dim ctl2 As Control       

 ' check to see Endorsement Data Entry is open    
bOpen = IsOpen("frmEndorsement")    
If Not bOpen Then        
   ' open form        
     DoCmd.OpenForm "frmEndorsement"    
End If        
Set frm2 = Forms!frmEndorsement        
' send data to frmEndorsement    
' look at each control on frmlEncounter    

For Each ctl In Me.Controls        
' only look at combo boxes and text boxes        
If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then 

' now look at each control on frmEndorsement           
For Each ctl2 In frm2                
   If TypeOf ctl2 Is TextBox Or TypeOf ctl2 Is ComboBox Then                    
' if the control names are the same,                
' set the value to that control on frmEndorsement
     If ctl.name = ctl2.name Then
     ctl2.Value = ctl.Value                    
     End If                
    End If            
Next ctl2        
End If    
Next ctl

Me.PCP = Forms!frmEndorsement!frmEndorsementSubform!PCP    
Me.EncountID = Forms!frmEndorsement!frmEndorsementSubform!EncountID
Me.mdsunit = Forms!frmEndorsement!frmEndorsementSubform!mdsunit      

End Sub
 
Old March 16th, 2006, 03:13 PM
Authorized User
 
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm a little confused because in your description you say that you want to move data from 'frmEncounter' to 'frmEndorsement' & 'frmEndorsementSubform' but in the code example below you are moving data from your 'frmEndorsementSubform' to 'frmEncounter'.


Me.PCP = Forms!frmEndorsement!frmEndorsementSubform!PCP


This doesn't matter though, you don't have to explain because I have another way for you to refer to a subform. The technique you use above is good for referring to a form but doesn't seem to work when referring to a subform (I've had this same problem before). So use the line of code below instead and see if that solves your problem when referring to subforms.

Me.PCP = Forms!frmEndorsement!frmEndorsementSubform.Forms.C ontrols.Item("PCP")

Let me know if this works for you or not.
Don






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to transfer value from one form to another cancertropica C# 2005 1 July 27th, 2008 02:42 PM
Using Internet Transfer Control to post XML jaforret Classic ASP XML 2 February 29th, 2004 02:43 PM
Deploying Internet Transfer Control in ASP alonsoca Classic ASP Professional 0 November 29th, 2003 07:13 PM
Internet Transfer Control HELP!!!!! kastronyc VB How-To 1 September 22nd, 2003 02:48 AM
Internet Transfer Control jake VB How-To 5 July 28th, 2003 04:59 AM





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