473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

FORM not affected by MODULE

1 New Member
MS Access: a MODULE in the common module bin is not recognized by the FORM for which I intended it. How do I inform the form to use the MODULE?
In the form properties I've used [Event Procedure] as ff (from Allen Browne (allen@allenbrowne.com))

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2.  Dim strMsg As String
  3.         Call CarryOver(Me, strMsg, "Itsohañe", "An-tsandry", "Toe'e", "Zoe-Afake")
  4.         If strMsg <> vbNullString Then
  5.             MsgBox strMsg, vbInformation
  6.         End If
  7. End Sub
in the Modules Bin of Access I copied the following, also from Allen Browne, and saved it as [COPYDOWN]
I've attached the full page from which I copied these two code items.

Thank you,
Steve
Attached Files
File Type: pdf Copy value from previous row.pdf (222.6 KB, 180 views)
Dec 8 '16 #1
1 933
jforbes
1,107 Recognized Expert Top Contributor
Can you paste a copy of your Module? The instructions at Assign default values from the last record are great, but they might be a bit confusing.

This code should be placed in the Form:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Form_BeforeInsert(Cancel As Integer)
  2.          Dim strMsg As String
  3.          Call CarryOver(Me, strMsg)
  4.          If strMsg <> vbNullString Then
  5.              MsgBox strMsg, vbInformation
  6.          End If

This code is the code that should be in the Module:
Expand|Select|Wrap|Line Numbers
  1. Public Function CarryOver(frm As Form, strErrMsg As String, ParamArray avarExceptionList()) As Long
  2. On Error GoTo Err_Handler
  3.     'Purpose: Carry over the same fields to a new record, based on the last record in the form.
  4.     'Arguments: frm               = the form to copy the values on.
  5.     '           strErrMsg         = string to append error messages to.
  6.     '           avarExceptionList = list of control names NOT to copy values over to.
  7.     'Return:    Count of controls that had a value assigned.
  8.     'Usage:     In a form's BeforeInsert event, excluding Surname and City controls:
  9.     '               Call CarryOver(Me, strMsg, "Surname", City")
  10.     Dim rs As DAO.Recordset         'Clone of form.
  11.     Dim ctl As Control              'Each control on form.
  12.     Dim strForm As String           'Name of form (for error handler.)
  13.     Dim strControl As String        'Each control in the loop
  14.     Dim strActiveControl As String  'Name of the active control. Don't assign this as user is typing in it.
  15.     Dim strControlSource As String  'ControlSource property.
  16.     Dim lngI As Long                'Loop counter.
  17.     Dim lngLBound As Long           'Lower bound of exception list array.
  18.     Dim lngUBound As Long           'Upper bound of exception list array.
  19.     Dim bCancel As Boolean          'Flag to cancel this operation.
  20.     Dim bSkip As Boolean            'Flag to skip one control.
  21.     Dim lngKt As Long               'Count of controls assigned.
  22.  
  23.     'Initialize.
  24.     strForm = frm.Name
  25.     strActiveControl = frm.ActiveControl.Name
  26.     lngLBound = LBound(avarExceptionList)
  27.     lngUBound = UBound(avarExceptionList)
  28.  
  29.     'Must not assign values to the form's controls if it is not at a new record.
  30.     If Not frm.NewRecord Then
  31.         bCancel = True
  32.         strErrMsg = strErrMsg & "Cannot carry values over. Form '" & strForm & "' is not at a new record." & vbCrLf
  33.     End If
  34.     'Find the record to copy, checking there is one.
  35.     If Not bCancel Then
  36.         Set rs = frm.RecordsetClone
  37.         If rs.RecordCount <= 0& Then
  38.             bCancel = True
  39.             strErrMsg = strErrMsg & "Cannot carry values over. Form '" & strForm & "' has no records." & vbCrLf
  40.         End If
  41.     End If
  42.  
  43.     If Not bCancel Then
  44.         'The last record in the form is the one to copy.
  45.         rs.MoveLast
  46.         'Loop the controls.
  47.         For Each ctl In frm.Controls
  48.             bSkip = False
  49.             strControl = ctl.Name
  50.             'Ignore the active control, those without a ControlSource, and those in the exception list.
  51.             If (strControl <> strActiveControl) And HasProperty(ctl, "ControlSource") Then
  52.                 For lngI = lngLBound To lngUBound
  53.                     If avarExceptionList(lngI) = strControl Then
  54.                         bSkip = True
  55.                         Exit For
  56.                     End If
  57.                 Next
  58.                 If Not bSkip Then
  59.                     'Examine what this control is bound to. Ignore unbound, or bound to an expression.
  60.                     strControlSource = ctl.ControlSource
  61.                     If (strControlSource <> vbNullString) And Not (strControlSource Like "=*") Then
  62.                         'Ignore calculated fields (no SourceTable), autonumber fields, and null values.
  63.                         With rs(strControlSource)
  64.                             If (.SourceTable <> vbNullString) And ((.Attributes And dbAutoIncrField) = 0&) _
  65.                                 And Not (IsCalcTableField(rs(strControlSource)) Or IsNull(.Value)) Then
  66.                                 If ctl.Value = .Value Then
  67.                                     'do nothing. (Skipping this can cause Error 3331.)
  68.                                 Else
  69.                                     ctl.Value = .Value
  70.                                     lngKt = lngKt + 1&
  71.                                 End If
  72.                             End If
  73.                         End With
  74.                     End If
  75.                 End If
  76.             End If
  77.         Next
  78.     End If
  79.  
  80.     CarryOver = lngKt
  81.  
  82. Exit_Handler:
  83.     Set rs = Nothing
  84.     Exit Function
  85.  
  86. Err_Handler:
  87.     strErrMsg = strErrMsg & Err.Description & vbCrLf
  88.     Resume Exit_Handler
  89. End Function
  90.  
  91. Private Function IsCalcTableField(fld As DAO.Field) As Boolean
  92.     'Purpose: Returns True if fld is a calculated field (Access 2010 and later only.)
  93. On Error GoTo ExitHandler
  94.     Dim strExpr As String
  95.  
  96.     strExpr = fld.Properties("Expression")
  97.     If strExpr <> vbNullString Then
  98.         IsCalcTableField = True
  99.     End If
  100.  
  101. ExitHandler:
  102. End Function
  103.  
  104. Public Function HasProperty(obj As Object, strPropName As String) As Boolean
  105.     'Purpose: Return true if the object has the property.
  106.     Dim varDummy As Variant
  107.  
  108.     On Error Resume Next
  109.     varDummy = obj.Properties(strPropName)
  110.     HasProperty = (Err.Number = 0)
  111. End Function
Dec 8 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason Charalambides | last post by:
Is there a way I can import a given value to a variable from the main form to a module? I wanted to have some routines that are repeated set in a module subroutine. However, the value of a...
1
by: Mustafa | last post by:
dear sir In my vb.net window application i have the MDI form MainMDI and child form form1 adn module as MainModule In my MainMDI Parent form i have one toolbar i.e. tbraction. I am trying to show...
2
by: dixie | last post by:
I know I've asked this before, but the answer elludes me and the message has long since disappeared from my newsgroup messages. How do you save a record using vba from a button or as part of an...
4
by: dixie | last post by:
I came across a lot of repetitious code in a form module that I would like to put in a module that I can call multiple times from a form. The problem I have run into is that when I put the code...
1
by: joye | last post by:
Hi, I know how the show a MessageBox in Form.h module by using VC.NET. But I don't know how to show the MessageBox at another class such as task.cpp which called by the Form.h; my question is...
3
by: Eric | last post by:
I had a windows form project that had a functions module that could control objects on the referenced main form. How would I do the same with a web project using a web form? See my windows form...
1
by: mgoold2002 | last post by:
Here is the offending excerpt from my code. I just began trying to port some vb code I'd written into my first .NET app. Public Class bannergenerator 'THIS IS AN ORDINARY WINDOWS FORM Inherits...
8
by: glamster7 | last post by:
Ok folks its Friday & I'm feeling a bit thick (also not very well). I have a form Salonmanagerdetail wich allows the user to enter the following details Stylist_Id,Stylist_Name,Group_Name &...
5
kirubagari
by: kirubagari | last post by:
I want to call a form from a module. My code as below Dim oGetHoldForm As frmHold If sActionType = "HOLD" Then Set oGetHoldForm = frmHold End If Im having...
1
kirubagari
by: kirubagari | last post by:
Dear expert, i had written the code in my form Public Function HoldType(ByRef sType As String) As String If bOkClicked Then sType = "Rehold " End If
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.