Modules & VBA :: Auto Initialize Class Module
Sep 16, 2013How you automatically initialize a newly instantiated class?
So when you create a new instance it will run a procedure to set attributes.
How you automatically initialize a newly instantiated class?
So when you create a new instance it will run a procedure to set attributes.
I am trying to pass a boolean variable to a class module
Code:
Set rps.ViewS = View
the code in the module that this in theory is calling reads as
Code:
Private ViewC As Boolean
Public Property Set ViewS(ByRef ViewA As Boolean)
Set ViewC = ViewA
End Property
Public Property Get ViewS() As Boolean
Set ViewS = ViewC
End Property
However I am getting the error message
Quote:Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter.
Sometimes we need a one-line function to just get the database path or things like that we cannot do on a query or on a Macro Object.
Like:
Function GetDatabasePath() = currentproject.path
possible?
I get the message "The expression On Click you entered as the event property setting produced the following error: Class does not support Automation or does not support expected interface"
I receive the message on a PC running Windows 7 Professional using the Access 2013 Runtime. This pc does not have Access 2013 installed.On my pc, I do not get the error. I have Access 2013 installed and run Windows 7 Professional SP1. The "code" which gives the error is as follows and is invoked by clicking a button on a form
Code:
MsgBox "1"
Dim rst As ADODB.Recordset
MsgBox "2"
Set rst = New ADODB.Recordset
MsgBox "3"
[code]....
The error takes place after Msgbox "2" and before Msgbox "3".The strange thing is that I can run without a problem a sophisticated software package on the pc which gives the error, using Access 2013 Runtime. This package I converted from Access 2003.
I have this below which some people cant run and some people can. All are using 2010 runtime version. Apart from the one guy who can run the macro who has full 2010 version. I have 2010 runtime installed and i can also run the macro fine.
Private Sub Option12_Click()
On Error GoTo Option12_Click_err
Dim CntlPay As String
Dim Lable As String
CntlPay = "D"
[code]....
I have wrote a database in access 2010 and the database works fine for me (I am the db admin with full control).I gave the database to a group in which most of them also have no issue with the file. They are able to use the database with no issues..One of those members gets an error message when completing the initial step in the database: (select a drop down item from a combo box)
Code:
The expression After Update you entered as the event propoerty setting produced the following error: Object or class does not support the set of events
Something I cant seem to understand is why is this happoening on 5 machines but not on the 6th, they all have the same PC set up so there should be no error on one particular machine.
I have two class variables (both arrays) among about 10 other class variables, that are not returning any values but "" for the string or #12:00:00AM" for a date. Here are my class variables:
Code:
'UPSData Class Module
Private p_LetterArray() As String
Private p_date() As Date
Private p_LetterArraySize As Integer
My Properties
Code:
'Properties
Public Property Get LetterArray(index As Integer) As String
LetterArray(index) = p_LetterArray(index)
End Property
Public Property Let LetterArray(index As Integer, NewValue As String)
[Code] ....
As I said, tLet and tDate result in "" and #12:00:00AM# respectively. When I step through the code, the values for tmp.LetterArray(0) is assigned "src" and tmp.UPSDate(0) stores "12/25/2013" correctly.
When I assign tLet and TDate, the same thing happens when stepping through the code. I'll use the LetterArray property to describe what happens:
Get LetterArray is called. p_LetterArray(0) does equal "src"
Let LetterArray is called. NewValue is "src" and p_LetterArray is "src" when End Property is highlighted in the debugger
Scope returns to Get LetterArray with End Property highlighted. In checking the values, LetterArray(0) = ""
Same steps happen with the same results ("12:00:00AM" vice "")
Any way to make objects to support adjusting continuous form controls making them unique in a sense to be able to change info like captions or whatever.
I've been working with collections for a while now tapping into event handlers such as the mouse inputs and or sizing of objects real time using collections but I can't seem to nail down any un-documented way to serialize controls on a continuos form.
I have tried when the new user creates the record adding another control to the collections class tying it to the id of the record but still this does not seem to be enough.
I do not know if there is a paint method or something of the sort I can override to get the desired results and most people without even trying will tell you this can't be done but how many have said that you can't move and resize objects in access but we are doing that now...
I'm using Access 2003. In "References" (Tools > References > Browse...), I've added in "Microsoft Windows Common Controls 6.0 (SP6)" (c:windowssystem32mscomctl.ocx).
I've then created/inserted an instance of the control "Microsoft ListView Control 6.0 (SP6)" on a Form ("MyForm") and given the listvew control the Name "MyListView".I wanted to decorate MyListView with some custom methods so I've created a new class module ("DecoratedListView") which contains a member field called "lvw".
I want 'lvw' to point/reference to MyListView, but I don't know what reference type to use in its declaration. Importantly, I also want to capture lvw's ColumnClick event.
I've tried:
Code:
Public WithEvents lvw As Object
Public WithEvents lvw As Control
Public WithEvents lvw As MSComctlLib.ListView.2
Public WithEvents lvw As MSComctlLib.ListView
Public WithEvents lvw As CustomControl
and none works when I
Code:
set lvw = Forms!MyForm.MyListView
The first try (Object) doesn't even compile. I get the exception "Expected: identifier"
The second try (Control) doesn't compile either. I get the exception "Object does not source automation events"
The third try (MSComctlLib.ListView.2) doesn't compile and throws the exception "Expected: end of statement"
The fourth try (MSComctlLib.ListView) compiles but fails at runtime with the exception "Type mismatch". Using TYPENAME() on the control returns "CustomControl".
The fifth try (CustomControl) compiles but fails at runtime with the exception "Object or class does not support the set of events".
I can't believe I'm the first person to have tried to capture an ActiveX Control's events in a separate class.
Basically I have a class event that works for all controls on any userform.
Its all working fine but I can't add an event to trap the click or mouse move of the userform itself.
Basically so when the cursor moves away from a control the label clears.
User Form Code
Code:
Option Compare Database
Option Explicit
'Define a collection and initialise the commandbutton event class
Private col As New Collection
Private newCmd As New clsEvents
[Code] .....
And here is the class Module
Code:
Option Compare Database
Option Explicit
'catch the event of Commandbuttons
Private WithEvents C0 As SubForm
'Private WithEvents C1 As CheckBox
[Code] ....
I've been playing around with creating my own class in VBA but I'm having problems calling its methods. My class is pretty basic, its called cDentist and the properties are just Name, Address, DOB etc and one method AddDentist. AddDentist will add the details to a sql server table.
So I create an instance of the class in a module called Dentist. At the very top of the code i put..
Code:
Option Compare Database
Global Dentist As cDentist
I have a method then in module Dentist, where I initialise the instance of class cDentist and i populate it's properities...
Code:
Sub RecordDentistDetails()
Set Dentist = New cDentist
Dentist.Name = Forms!frm_enterdetails!txtName
[Code].....
When I click 'Save' I get error, Method or data member not found. And '.AddDentist' is highlighted. I'm a little confused why it's not seeing AddDentist as a method of class cDentist.
I'm wondering how other members here make decisions whether they want to place codes behind form or use a standard module instead.
I understand there is a performance penalty when you add another module (and use it), but am not sure whether one big fat module would be faster than several smaller modules with identical coding.
Furthermore, I know that some members use a hidden form to deal with startup and shutdown processing. Sometimes the processing has nothing to do with forms and would make more sense in a standard module, but since the form is already loaded, does it makes more sense to use the module behind the form than calling a function in a separate standard module to execute the needed code?
So, what do you tend to do in such situation?
I haven't created classes in a while, and I don't see what is the problem
I'm modifying a function to get fractions from double. It worked well, but it returned a string.
I need it to be in parts, so I created this class
Code:
Option Compare Database
Public Entier As Integer
Public nominateur As Integer
Public denominateur As Integer
Public Function getText()
getText = Entier & " " & nominateur & "/" & denominateur
End Function
I changed the function type and the assignation:
Code:
Function GetFraction(ByVal Num As Double) As nombreEnFraction
Set GetFraction = New nombreEnFraction
If Num = 0# Then
GetFraction = "None"
Else
Dim WholeNumber As Integer
Dim DecimalNumber As Double
[Code] ....
For some reasons, when I get to the end of the function, I get a 91 error, like if it was nothing
But when I use a spy, I see values in the object until the end.
I have a parent form which has a class variable (class module instance) to store the form' status and more.... and when i add a new record to the subform it resets the class variable field' data. but this only happens on first transaction, but if i re-run the steps (re-set the variable field value) it's not happening again.
View 3 Replies View RelatedI'm trying to subtotal data in an excel file but I am getting a subtotal method of Range class failed in the red text below. I have been trying to get this to work with no success.
Code:
Public Function SUMMARY()
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
With xlApp
Dim wb As Object
[Code] .....
I have a small system that consists of a back end data base and 2 front ends. having 2 front ends was a historic reason but they cover 2 distinct processes in the system.
I now have the need for using the same module(s) in both front ends. Each has a copy which is fine if nothing changes but when it does I have to apply the changes made (or copy over in its entirety) from one front end to the other.
Although this is no big deal I can forsee it slipping through the net.
Can 2 front ends access the SAME module and if so how?
This is the code I'm trying to run from a Standard Module:
Code:
Public Sub RunPaxCalculations()
Dim frm As Form
Dim intNumberOfRecordsInFilter
[Code]....
I want to put some form functions into a module.here is what I currently have in the module:
Public Sub Fun_Test()
Forms!Form_Output!Sequence.ColumnWidth = 250
End Sub
my form name is "Form_Output" but it still cant find it..
I have this code below that is working however the calculation are updating on my form late.
Basically, I have some calculation that are performed on a "After Update" event on some controls on my form. I wanted it to do the calculation after I update the control on the form.
The code is in a module and I just call the function after update on the control But the form is not updating when I change the value in a field. I have to change the field again for it to update.
Control
Code:
Call GeraAuditCalc
DoCmd.RefreshRecord
Function
Code:
Function GeraAuditCalc()
Dim fHrs As Double
Dim Ttl As Double
Dim Ttl1 As Double
Dim Ttl2 As Double
[Code] ....
I am trying to return a value in an expression (call it FundedPeriod): CurrentWeek, CurrentMonth, PreviousMonth, based on a date value in field [funded_date].
Here are the criteria I am using:
Current Week: DatePart("ww", [Funded_Date]) = DatePart("ww", Date()) and Year([Funded_Date]) = Year(Date())
Current Month: Year([Funded_Date]) = Year(Now()) And Month([Funded_Date]) = Month(Now())
Previous Month: Year([Funded_Date])* 12 + DatePart("m", [Funded_Date]) = Year(Date())* 12 + DatePart("m", Date()) - 1
Based on example, I expanded upon that and came up with this:
Code:
Function FundedPeriod(FD)
' returns CurrentWeek or CurrentMonth or PreviousMonth or None based on FundedDate (FD) criteria
Dim ret As Boolean
ret=CurrentWeek
[Code] ....
Am I in the ballpark w/ this in order to return:
CurrentWeek or CurrentMonth or PreviousMonth
so in the query expression I think I would type FundedPeriodName: FundedPeriod([funded_date])
An instance of a form can be opened with:
Dim frm As Form
Set frm = New Form_formname
How can this be done using a variable as the formname?
I have the following module in my database to allow for multiple alarms.
It all works great, except before showing the actual alarm record called, the form first pops up showing the first record in its record source.
I.e. it flashes up showing the first record in the table, then changes to the 'correct' record.
I would just like to change it so it either doesn't show until the record is loaded, or it shows blank to begin with.
Here's the module...
Code:
Option Compare Database
Option Explicit
Public clnPopUpAlarm As New Collection 'Instances of frmPopUpAlarm
[Code].....
I'm trying to monitor a few fields and record who updated them together with the old and new values, so far, I have this;
This does work ok, I was just wondering if there's a way of referring to the current field, rather than having to specify 'me.NPW.oldvalue' etc.
Code:
Private Sub NPW_AfterUpdate()
Call LogFieldUpdate(Me.AppNumber, "NPW", Me.NPW.OldValue, Me.NPW)
End Sub
[Code] ......
This module is giving me the "undefined function" error message when I try to run my query. I don't know why, but I have checked that there are no references with "missing" and there are not. I also added the word "Public" to the function becasue that was advised by another forum user. I thought it worked perfectly the first time I ran this query, but now it is not working and I do not recall making any changes. I have called the module basFunctions:
Option Compare Database
'************************************************* *********
'Declarations section of the module
'************************************************* *********
Option Explicit
'================================================= =========
' The DateAddW() function provides a workday substitute
' for DateAdd("w", number, date). This function performs
' error checking and ignores fractional Interval values.
'================================================= =========
Public Function DateAddW(ByVal TheDate, ByVal Interval)
Dim Weeks As Long, OddDays As Long, Temp As String
[code].....
I have a back end database that a number of people are working with using an Excel add-in that imports and edits records saved in the backend. Occasionally, when a user will update a record at first it saves to the backend but then an hour or two later, the changes made disappear. We have validated that after the user saves the changes, those changes are present in the backend of the database, but for some reason those changes disappear after a period of time.
View 7 Replies View RelatedCan't find any way to declare variables in the sort of module that Access uses by default.Having changed the default, I now get 'Option Compare Database' as the first line (previously nothing was there). Adding anything at all in that section, or changing it to 'Option Explicit' has the consistent effect that all the procedure names in the module are not recognised and nothing works.
Variables declared in procedures work only in the procedure even if declared as Public. Can't get a Static variable to work in more than one procedure. However many variables I declare, there are never any in the Declarations list at the top of the Code Window.