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)) - Private Sub Form_BeforeInsert(Cancel As Integer)
-
Dim strMsg As String
-
Call CarryOver(Me, strMsg, "Itsohañe", "An-tsandry", "Toe'e", "Zoe-Afake")
-
If strMsg <> vbNullString Then
-
MsgBox strMsg, vbInformation
-
End If
-
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
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: - Private Sub Form_BeforeInsert(Cancel As Integer)
-
Dim strMsg As String
-
Call CarryOver(Me, strMsg)
-
If strMsg <> vbNullString Then
-
MsgBox strMsg, vbInformation
-
End If
This code is the code that should be in the Module: - Public Function CarryOver(frm As Form, strErrMsg As String, ParamArray avarExceptionList()) As Long
-
On Error GoTo Err_Handler
-
'Purpose: Carry over the same fields to a new record, based on the last record in the form.
-
'Arguments: frm = the form to copy the values on.
-
' strErrMsg = string to append error messages to.
-
' avarExceptionList = list of control names NOT to copy values over to.
-
'Return: Count of controls that had a value assigned.
-
'Usage: In a form's BeforeInsert event, excluding Surname and City controls:
-
' Call CarryOver(Me, strMsg, "Surname", City")
-
Dim rs As DAO.Recordset 'Clone of form.
-
Dim ctl As Control 'Each control on form.
-
Dim strForm As String 'Name of form (for error handler.)
-
Dim strControl As String 'Each control in the loop
-
Dim strActiveControl As String 'Name of the active control. Don't assign this as user is typing in it.
-
Dim strControlSource As String 'ControlSource property.
-
Dim lngI As Long 'Loop counter.
-
Dim lngLBound As Long 'Lower bound of exception list array.
-
Dim lngUBound As Long 'Upper bound of exception list array.
-
Dim bCancel As Boolean 'Flag to cancel this operation.
-
Dim bSkip As Boolean 'Flag to skip one control.
-
Dim lngKt As Long 'Count of controls assigned.
-
-
'Initialize.
-
strForm = frm.Name
-
strActiveControl = frm.ActiveControl.Name
-
lngLBound = LBound(avarExceptionList)
-
lngUBound = UBound(avarExceptionList)
-
-
'Must not assign values to the form's controls if it is not at a new record.
-
If Not frm.NewRecord Then
-
bCancel = True
-
strErrMsg = strErrMsg & "Cannot carry values over. Form '" & strForm & "' is not at a new record." & vbCrLf
-
End If
-
'Find the record to copy, checking there is one.
-
If Not bCancel Then
-
Set rs = frm.RecordsetClone
-
If rs.RecordCount <= 0& Then
-
bCancel = True
-
strErrMsg = strErrMsg & "Cannot carry values over. Form '" & strForm & "' has no records." & vbCrLf
-
End If
-
End If
-
-
If Not bCancel Then
-
'The last record in the form is the one to copy.
-
rs.MoveLast
-
'Loop the controls.
-
For Each ctl In frm.Controls
-
bSkip = False
-
strControl = ctl.Name
-
'Ignore the active control, those without a ControlSource, and those in the exception list.
-
If (strControl <> strActiveControl) And HasProperty(ctl, "ControlSource") Then
-
For lngI = lngLBound To lngUBound
-
If avarExceptionList(lngI) = strControl Then
-
bSkip = True
-
Exit For
-
End If
-
Next
-
If Not bSkip Then
-
'Examine what this control is bound to. Ignore unbound, or bound to an expression.
-
strControlSource = ctl.ControlSource
-
If (strControlSource <> vbNullString) And Not (strControlSource Like "=*") Then
-
'Ignore calculated fields (no SourceTable), autonumber fields, and null values.
-
With rs(strControlSource)
-
If (.SourceTable <> vbNullString) And ((.Attributes And dbAutoIncrField) = 0&) _
-
And Not (IsCalcTableField(rs(strControlSource)) Or IsNull(.Value)) Then
-
If ctl.Value = .Value Then
-
'do nothing. (Skipping this can cause Error 3331.)
-
Else
-
ctl.Value = .Value
-
lngKt = lngKt + 1&
-
End If
-
End If
-
End With
-
End If
-
End If
-
End If
-
Next
-
End If
-
-
CarryOver = lngKt
-
-
Exit_Handler:
-
Set rs = Nothing
-
Exit Function
-
-
Err_Handler:
-
strErrMsg = strErrMsg & Err.Description & vbCrLf
-
Resume Exit_Handler
-
End Function
-
-
Private Function IsCalcTableField(fld As DAO.Field) As Boolean
-
'Purpose: Returns True if fld is a calculated field (Access 2010 and later only.)
-
On Error GoTo ExitHandler
-
Dim strExpr As String
-
-
strExpr = fld.Properties("Expression")
-
If strExpr <> vbNullString Then
-
IsCalcTableField = True
-
End If
-
-
ExitHandler:
-
End Function
-
-
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
-
'Purpose: Return true if the object has the property.
-
Dim varDummy As Variant
-
-
On Error Resume Next
-
varDummy = obj.Properties(strPropName)
-
HasProperty = (Err.Number = 0)
-
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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 &...
|
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...
|
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
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |