Rabu, 22 Februari 2017

Re: [MS_AccessPros] How to call this function from forms.

 

Duane-

What if the LinkMasterField and LinkChildField are empty? How to apply the function? Thanks in advance.

Best Regards,
Kevin


On 2017/2/22 星期三 20:23, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] wrote:
 

Kevin

If everything else seems to work I would add code that basically ignores error 2101

    Select Case Err.Number

      Case 2101

        Resume Next

      Case Else
        MsgBox "Error in linkSubForm: " & vbCr & Err.Description & vbCr & _
               " Number: " & Str(Err.Number)
        Resume Next
    End Select





From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of 'Kevin Z.' qingqinga@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, February 22, 2017 5:58 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] How to call this function from forms.
 


Duane-
Here's the code. There's no space in the linking field names.

Private Sub Command2_Click()
On Error GoTo ErrHandle

linkSubForm Me, "subFormFrame", "HotelID", "HotelID", , "subHotelContact"

ErrExit:
    Exit Sub
    
ErrHandle:
    Resume ErrExit

End Sub

Best Regards,
Kevin

On 2017/2/22 18:49, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] wrote:
 

Kevin,

We already had that code. We need the code you added to the main form to set the subform. 


Do you have spaces in your linking field names?


Regards,

Duane




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of 'Kevin Z.' qingqinga@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, February 22, 2017 4:24 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] How to call this function from forms.
 


Duane-

Yes, the correct subform shows.
But an error message showed twice before the subform shows. Here's the code:

Option Compare Database
Option Explicit
Public bolLinkSubForm As Boolean    'Global durch Public ersetzt by Willi Wipp

' Author : Christian Coppes
' Version: V1.3
' Last Modified: 29.06.2007
'
'  Update link to a subform (name in "strSubform")
'  strChild and strMaster = Indices which should be linked
'  between main form and subform.
'  Name of the subform and name of the subform-container must be identical,
'  if strSubForm is left
Public Sub linkSubForm(frm As Form, strSubFormContainer As String, _
                       strChild As String, strMaster As String, _
                       Optional strRecSource As String, _
                       Optional strSubForm As String)
On Error GoTo Fehler
    bolLinkSubForm = True
    Application.Echo False
    If strSubForm = "" Then strSubForm = strSubFormContainer
    ' necessary following MS-instructions
    frm(strSubFormContainer).LinkChildFields = ""
    ' necessary following MS-instructions
    frm(strSubFormContainer).LinkMasterFields = ""
    frm(strSubFormContainer).SourceObject = strSubForm
    If (strChild <> "" And strMaster <> "") Then
        frm(strSubFormContainer).LinkChildFields = strChild
        frm(strSubFormContainer).LinkMasterFields = strMaster
    End If
    If strRecSource <> "" Then
        frm(strSubFormContainer).Form.RecordSource = strRecSource
    End If
    Application.Echo True
    bolLinkSubForm = False
    Exit Sub
Fehler:
    Application.Echo True
    Select Case Err.Number
      Case Else
        MsgBox "Error in linkSubForm: " & vbCr & Err.Description & vbCr & _
               " Number: " & Str(Err.Number)
        Resume Next
    End Select
End Sub

Best Regards,

Kevin

On 2017/2/22 18:10, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] wrote:
 

Kevin,


Provide your code.


Can we confirm the correct subform shows?

Are the link properties set okay?


Regards,

Duane




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of 'Kevin Z.' qingqinga@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, February 22, 2017 2:47 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] How to call this function from forms.
 


Duane-

It worked! But I got a Error message as well saying "Error in linkSubForm: The setting you entered isn't valid for this property. Number: 2101". Anything could be wrong? Thanks.

Best Regards,
Kevin

On 2017/2/22 16:31, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] wrote:
 

Kevin,

If you are running the code from some event in the form "frmHotel" then try:

 linkSubForm Me, "subFormFrame", "HotelID", "HotelID", , "subHotelContact"

Regards,
Duane Hookom
Vevey, Switzerland


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of 'Kevin Z.' qingqinga@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, February 22, 2017 2:00 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] How to call this function from forms.
 


Dear Duane,

Thanks for you reply. Here are the actual items:

mainForm: frmHotel
subFormContainer: subFormFrame
subForm: subHotelContact
Link: HotelID

In this case, how to apply the function? Thanks.


Best Regards,
Kevin



On 2017/2/22 15:32, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] wrote:
 

Kevin,

The code in your post was a bit garbled in my IN BOX so I have reformatted and added a couple lines of comments
  ' call from a main form with code like
   '   linkSubForm Me, "sfrmMySfName", "EmployeeID", "EmployeeID"

If you provided some actual subform control and object names as well as the linking fields, we could help a bit more.

Option Compare Database 
Option Explicit 
Public bolLinkSubForm As Boolean 
'Global durch Public ersetzt by Willi Wipp 
' Author : Christian Coppes 
' Version: V1.3 
' Last Modified: 29.06.2007 
' ' Update link to a subform (name in "strSubform") 
' strChild and strMaster = Indices which should be linked 
' between main form and subform. 
' Name of the subform and name of the subform-container must be identical, 
' if strSubForm is left 
Public Sub linkSubForm(frm As Form, strSubFormContainer As String, _
       strChild As String, strMaster As String, _
       Optional strRecSource As String, _
       Optional strSubForm As String) 
   ' call from a main form with code like
   '   linkSubForm Me, "sfrmMySfName", "EmployeeID", "EmployeeID"
   On Error GoTo Fehler 
   bolLinkSubForm = True 
   Application.Echo False 
   If strSubForm = "" Then
       strSubForm = strSubFormContainer ' necessary following MS-instructions 
       frm(strSubFormContainer).LinkChildFields = "" ' necessary following MS-instructions 
       frm(strSubFormContainer).LinkMasterFields = "" 
       frm(strSubFormContainer).SourceObject = strSubForm 
       If (strChild <> "" And strMaster <> "") Then
          frm(strSubFormContainer).LinkChildFields = strChild 
          frm(strSubFormContainer).LinkMasterFields = strMaster 
       End If 
       If strRecSource <> "" Then
         frm(strSubFormContainer).Form.RecordSource = strRecSource 
   End If 
   Application.Echo True 
   bolLinkSubForm = False 
Exit Sub Fehler: 
   Application.Echo True 
   Select Case Err.Number
       Case Else MsgBox "Error in linkSubForm: " & vbCr & Err.Description & vbCr & _ " Number: " & Str(Err.Number) 
          Resume Next 
   End Select 
End Sub

Regards,
Duane Hookom
Vevey, Switzerland



From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of 'qingqinga@yahoo.com' qingqinga@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, February 21, 2017 10:31 PM
To: MS_Access_Professionals
Subject: [MS_AccessPros] How to call this function from forms.
 


Dear All,

I got this code below from a website. Can anybody give me an example on how to call this function from forms. Thanks in advance.

Option Compare Database Option Explicit Public bolLinkSubForm As Boolean 'Global durch Public ersetzt by Willi Wipp ' Author : Christian Coppes ' Version: V1.3 ' Last Modified: 29.06.2007 ' ' Update link to a subform (name in "strSubform") ' strChild and strMaster = Indices which should be linked ' between main form and subform. ' Name of the subform and name of the subform-container must be identical, ' if strSubForm is left Public Sub linkSubForm(frm As Form, strSubFormContainer As String, _ strChild As String, strMaster As String, _ Optional strRecSource As String, _ Optional strSubForm As String) On Error GoTo Fehler bolLinkSubForm = True Application.Echo False If strSubForm = "" Then strSubForm = strSubFormContainer ' necessary following MS-instructions frm(strSubFormContainer).LinkChildFields = "" ' necessary following MS-instructions frm(strSubFormContainer).LinkMasterFields = "" frm(strSubFormContainer).SourceObject = strSubForm If (strChild <> "" And strMaster <> "") Then frm(strSubFormContainer).LinkChildFields = strChild frm(strSubFormContainer).LinkMasterFields = strMaster End If If strRecSource <> "" Then frm(strSubFormContainer).Form.RecordSource = strRecSource End If Application.Echo True bolLinkSubForm = False Exit Sub Fehler: Application.Echo True Select Case Err.Number Case Else MsgBox "Error in linkSubForm: " & vbCr & Err.Description & vbCr & _ " Number: " & Str(Err.Number) Resume Next End Select End Sub
Best Regards,
Kevin

















__._,_.___

Posted by: "Kevin Z." <qingqinga@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (14)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar