First of all, you should know, that some of functions, used on the worksheet, have limitations. So my point is avoid of using them in VBA, if it is not necessary.
For example, function POWER()
returns error on attempt to raise a zero to zero. An alternative is to use 0 ^ 0
combination, which is exactly doing the same, but looks more simply and operates without such error.
But also there is no embedded alternative in VBA to the FACT()
function, so you can use it, or simply add your own function factor()
— it’s uppon your choise.
If you just have started learning VBA, I would recomend you to use Option Explicit
. It will help you to find out, which variables are not defined, and sometimes to avoid errors related to variable names missprint.
Here is your code, fixed and a little bit optimized:
Option Explicit' It is an option that turns on check for every used variable to be defined before execution. If this option is not defined, your code below will find undefined variables and define them when they are used. Good practice is to use this option, because it helps you, for example to prevent missprinting errors in variable names.
Sub Bezier()
Dim C as Double , t As Double
Dim k As Long, n As Long, i As Long
n = 3
For i = 0 To 100
t = i * 0.01
Cells(i + 2, 6) = 0
Cells(i + 2, 7) = 0
For k = 0 To n
C = (WorksheetFunction.Fact(n) / WorksheetFunction.Fact(k)) / WorksheetFunction.Fact(n - k)
Cells(i + 2, 6) = Cells(i + 2, 6).Value + Cells(k + 2, 1).Value * C * (t ^ k) * ((1 - t) ^ (n - k))
Cells(i + 2, 7) = Cells(i + 2, 7).Value + Cells(k + 2, 2).Value * C * (t ^ k) * ((1 - t) ^ (n - k))
Next
Next
End Sub
UPDATE
Here are some examples of factorial calculations.
Public Function fnFact(number) ' a simple cycle example of Factorial function
Dim tmp As Long ' new temporary variable to keep the "number" variable unchanged
tmp = number
fnFact = number
While tmp > 1
tmp = tmp - 1
fnFact = fnFact * tmp
Wend
End Function
Public Function fnFactR(number) ' a simple example of recursive function for Factorial calculation
If number > 0 Then
fnFactR = fnFactR(number - 1) * number ' function calls itself to continue calculations
Else
fnFactR = 1 ' function returns {1} when calculations are over
End If
End Function
Sub Factor_test() 'RUN ME TO TEST ALL THE FACTORIAL FUNCTIONS
Dim number As Long
number = 170 ' change me to find Factorial for a different value
MsgBox "Cycle Factorial:" & vbNewLine & number & "!= " & fnFact(number)
MsgBox "WorksheetFunction Factorial:" & vbNewLine & number & "!= " & WorksheetFunction.Fact(number)
MsgBox "Recursive Factorial:" & vbNewLine & number & "!= " & fnFactR(number)
End Sub
All those functions are available to calculate Factorial only for numbers before 170 inclusively, because of large result value.
So for my PC the limitation for WorksheetFunction.Fact()
function is also 170.
Let me know, if your PC has different limitation for this function, — it’s quite interesting thing.
UPDATE2
It is recomended to use Long
data type instead of Integer
each type when integer (or whole number) variable is needed. Long
is slightly faster, it has much wider limitations and costs no additional memory. Here are proof links:
1. MSDN:The Integer, Long, and Byte Data Types
2. ozgrid.com:Long Vs Integer
3. pcreview.co.uk:VBA code optimization — why using long instead of integer?
Thanks for @Ioannis and @chris neilsen for the information about Long
data type and proof links!
Good luck in your further VBA actions!
I have the following class module BlSecurity
in my Access database:
Option Compare Database
Option Explicit
Private tiendaRepo As ITiendaRepository
Public Sub Init(ptiendaRepo As ITiendaRepository)
tiendaRepo = ptiendaRepo
End Sub
Public Sub Login(code As String)
If tiendaRepo.CheckIfCodeExists(code) = "" Then
Err.Raise Number:=CustomErrors.CenterCodeNotExisting
End If
Exit Sub
End Sub
Private Sub Class_Terminate()
Set tiendaRepo = Nothing
End Sub
This is TiendaRepository code:
Option Compare Database
Option Explicit
Implements ITiendaRepository
Public Function ITiendaRepository_CheckIfCodeExists(ByVal code As String) As String
Err.Raise vbObjectError, "CheckCode", "Not implemented"
Exit Function
End Function
And this is the «interface» ITiendaRepository I’m implementing:
Option Compare Database
Option Explicit
Public Function CheckIfCodeExists(ByVal code As String) As String
End Function
Then, inside a button handler:
Private Sub btnLogin_Click()
Dim bl As blSecurity
Set bl = New blSecurity
bl.Init (New TiendaRepository)
bl.Login (txtUsuario.Value)
End Sub
But when I click the button, I receive message:
Object doesn’t support this property or method
in line bl.Init (New TiendaRepository)
. What’s wrong with it?
- Remove From My Forums
-
Question
-
Hi everyone,
I have an error 438 on all 7 buttons on a form, I will show you one of them hopefully if we can solve one, the others will be easier to solve.
Here is the form, the button I choose is the purple one:
Here is the code on that purple button:
Public Sub CanadianEMVPrePaidSale_Click() Dim dbs As DAO.Database Dim rst As DAO.Recordset Set dbs = CurrentDb Set rst = CurrentDb.OpenRecordset("FactureMERCURYTemp TOTAUX") ' this code example will serve for the Canadian EMV PrePaid Issues, Sales, Returns and Balance inquiries where ' card information is obtained from the PINPad. For PrePaid transactions with manually-entered account information, ' use the same code as for non-EMV PrePaid Sales -- there will be no EMV interaction in these cases. See ' PrePaidSaleExample() ' PrePaid Voids are also handled just like non-EMV PrePaid Void transactions, with no EMV interaction necessary. ' See PrePaidVoidSaleExample() ' Request object contains transaction information Dim request As New Transaction.request Dim response As New Transaction.response request.TenderType = TenderTypes_PrePaid ' Use PrePaid, not CanadianEMV... request.TransactionType = TransactionTypes_Sale ' Required transaction information request.GiftServers = "g1.mercurydev.net;g2.mercurydev.net" request.MerchantID = "MPS53001" ' Mercury Supplied, Token enabled MID. request.Memo = "[Auto-Caisse restaurant, Version 3.0]" ' Supply your POS product and version number request.UserID = rst![serveurTrans] ' UserID PA-DSS requirement logging request.InvoiceNumber = rst![Réf commande] request.ReferenceNumber = rst![Réf commande] request.CanadianEMVTerminalID = "TerminalID" ' optional terminal identifier request.MerchantLanguage = "French" ' required, "English" or "French" request.UserTraceData = "[Auto-Caisse restaurant, Version 3.0]" ' Supply your POS product and version number ' Set the amount of the transaction request.AmountData.PurchaseAmount = rst![Somme De mtTransApTaxes] ' EMV requires PINPad interaction. To communicate with the POS peripheral device, ' you must configure the PinPadConfig object Dim pinPadConfig As New Transaction.pinPadConfig pinPadConfig.PinPadType = PinPadType_VerifoneVX810CAEMVGlobal1 ' Verifone vx810 currently only ' supported peripheral for EMV pinPadConfig.MerchantID = "MPS53001" ' required, unique to position pinPadConfig.ComPort = 3 ' required, integer value between 1 - 254 pinPadConfig.SequenceNumber = "0010010010" ' required, pass value returned from previous transaction, ' default "0010010010" pinPadConfig.PinPadConnectionMethod = PinPadConnectionMethod_Serial ' Set the PinPadConfig property for each EMV request request.pinPadConfig = pinPadConfig ' MercuryShieldUI accepts the Request object to process the transaction Dim msui As New MercuryShield.MercuryShieldUI msui.ProcessTransactionNoUI Set response = msui.MercuryShieldResponse ' Handle Response here. End Sub
When debugging, the error shows on the bold line:
request.pinPadConfig = pinPadConfigThank you for your help
Claude from Quebec, Canada
Claude Larocque
Answers
-
It looks like the properties of request are not preceded by a naming convention…
——————————
Dim request As New Transaction.requestrequest.TenderType = TenderTypes_PrePaid
request.TransactionType = TransactionTypes_Sale
request.GiftServers = «g1.mercurydev.net;g2.mercurydev.net»
request.MerchantID = «MPS53001»
request.Memo = «[Auto-Caisse restaurant, Version 3.0]»
request.UserID = rst![serveurTrans]
request.InvoiceNumber = rst![Réf commande]
request.ReferenceNumber = rst![Réf commande]
request.CanadianEMVTerminalID = «TerminalID»
request.MerchantLanguage = «French»
request.UserTraceData = «[Auto-Caisse restaurant, Version 3.0]»
request.AmountData.PurchaseAmount = rst![Somme De mtTransApTaxes]Dim pinPadConfig As New Transaction.pinPadConfig
pinPadConfig.PinPadType = PinPadType_VerifoneVX810CAEMVGlobal1request.pinPadConfig = pinPadConfig
——————————
Except for the PadConfig property…
So, maybe:
request.PadConfig = pinPadConfig
or
Set request.PadConfig = pinPadConfigChris.
Brisbane Australia, GMT+10, Access 2003,
Public at SkyDrive-
Proposed as answer by
Friday, August 17, 2012 6:09 PM
-
Marked as answer by
Claude Larocque
Saturday, August 18, 2012 5:09 AM
-
Proposed as answer by
-
I don’t know your custom type but pinPadConfig looks like an Object to me. It looks to me that request is an Object which has the property pinPadConfig which is itself an Object.
To assign the Object pinPadConfig (that your statements assign different settings) the property pinPadConfig of the Object request, you need to use the keyword Set like:
Set request.pinPadConfig = pinPadConfig
Van Dinh
-
Marked as answer by
Claude Larocque
Saturday, August 18, 2012 5:09 AM
-
Marked as answer by
-
Hi Claude.
First part…
First up may I say I have absolutely no knowledge of that system and therefore this is just a guess. Having said that, I’m not at all sure you would see any indication that the code has executed.
The bottom of page 18 of the manual on your SkyDrive seems to indicate that msUI.ProcessTransactionNoUI is a silent transaction and that you may need to call msUI.ShowDialog to get some user display.
So, rather than:-
msui.ProcessTransactionNoUI
try:-
msUI.ShowDialogNote also that page 18 says a transaction which requires processTransactionNoUI, but instead calls ShowDialog, will result in an error: “Not Implemented.”
So, if you use msUI.ShowDialog and get a “Not Implemented” error then that may indicate that msui.ProcessTransactionNoUI is required and your code working correctly in silent mode.
Again, though, that is just a guess because I can’t test it.
Second part…
Some time ago you mentioned a drag and drop floor plan for a restaurant. At the time you indicated you wanted to use it for costing of table orders during service. I indicated such drag and drop on a touch screen would cause excessive abrasion to the screen
and I’ll stand by that.However, a touch screen should also allow the use of a mouse so I built a drag and drop floor plan demo using the mouse. It is not intended for costing during service but rather as a means by which a manager can pre-plan a floor layout after hours.
I envisage its use to pre-plan the floor layout for private restaurant bookings such as for weddings and the like. The idea being that, given the number of people, the type of event, the seating arrangement and any special wishers of the person making the booking,
the floor plan can be done on screen prior to the event. On the day a report can be printed to enable the staff to rearrange the restaurant.The demo is done to scale where 1 twip equals 2 millimetres. It would require each restaurant to make up an empty template of the size and shape of their premises. Once that is done the rest is fairly easy. Standard templates can then be built, reused, modified
and saved.If you care to use it the demo can be found on my SkyDrive in my signature under ‘Drag Floor Plan’. Please let me know if you have any problems or questions.
Drag Floor Plan
Chris.
Brisbane Australia, GMT+10, Access 2003,
Public at SkyDrive-
Edited by
Chris A O’Brien
Friday, August 17, 2012 11:14 PM -
Marked as answer by
Claude Larocque
Saturday, August 18, 2012 5:09 AM
-
Edited by
-
… I sent an email to the suppliers of the dll’s and I am waiting for an answer…
Sorry, Claude…
We don’t know your Custom Library / Class to be able to offer any help but emailing the DLL suppliers seems like the correct way to go…
Van Dinh
-
Marked as answer by
Claude Larocque
Saturday, August 18, 2012 5:09 AM
-
Marked as answer by
Return to VBA Code Examples
This article will demonstrate how to Fix VBA Error 438 – Object Doesn’t Support Property or Method.
Error 438 is a frequently occuring error in Excel VBA and is caused by either omitting a property or method when referring to an object, or by using a property or method that is not available to an object in the VBA code.
Check the VBA code to Fix Error 438
Let us examine the following code:
Sub RemoveWorksheet()
Dim wb As Workbook
Dim ws As Worksheet
Dim sheetName As String
sheetName = "Sheet 1"
Set wb = ActiveWorkbook
For Each ws In wb.Sheets
If ws = sheetName Then
wb.Sheets(sheetName).Delete
Exit For
End If
Next ws
End Sub
If we run this code, Error 438 will occur.
To resolve this issue, we click on Debug to see where the error is occurring.
This line of code is trying to equate the worksheet (depicted by the variable ws) to the sheet name. This is not possible as the worksheet is an object but the sheet name is a string so Error 438 is therefore returned.
To solve this, compare the string sheetName to the name property of the worksheet object:
ws.name = sheetName
Now the code runs without issue!
To show a list of all the properties or methods that are available to the worksheet object, we can type a dot (.) after the object.
This invokes the VBA Editor’s Intellisense feature. To make sure it’s turned on, in the Menu, select Tools > Options.
Make sure Auto List Members is checked and then click OK.
NOTE: This is usually on by default.
You can also find a list of all the Properties, Methods and Events for an Excel Object in the Object Browser.
In the Menu, select View > Object Browser or press F2 (See more VBE shortcuts).
A list of classes and objects will appear in the left hand side of the screen. If you click on the object you wish to use (eg: Workbook), a list of all the Properties, Methods and Events that that object supports will appear in the right hand side of the screen. (eg: Members of Workbook).
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro — A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!
Learn More!
We already know that this is the most frustrating Microsoft Visual Basic Runtime Error 438 VBA issue which you are getting in day-to-day life, So today we are surely here going to show you some top best accessible methods and solutions and some tips and tricks to get rid out of it permanently from your Windows PC as well on your device too if you are facing on it also.
This shows an error code message like,
When you are running a Visual Basic or running the Microsoft Excel 2000, then you might get this error problem. This error occurs when you are trying to use variables for workbooks & worksheet names. This Microsoft Visual Basic Runtime Error 438 VBA may also happen when you are running a program in which a form is assigned to a variable & that variable is used to access a control on the form. This error includes your PC system crashes, virus infection or sometimes freezes too. It also starts when you are trying to execute the BW query. This error may occur if the installed AMD drivers out of date.
Causes of Microsoft Visual Basic Runtime Error 438 VBA Issue:
- Microsoft Visual Basic runtime
- Windows PC error issue
- An object does not support this property or method epaceengagement
So, here are some quick tips and tricks for efficiently fixing and resolve this type of Microsoft Visual Basic Runtime Error 438 VBA Windows PC Code issue from you permanently.
How to Fix & Solve Microsoft Visual Basic Runtime Error 438 VBA Issue
1. Disable the Enhanced Protected Mode from Internet Explorer –
- Open Internet Explorer
- Click on the tools option there, on the right side
- Click on the Internet Options there
- On the Advanced option,
- Uncheck the option box for “Enable Enhanced Protected Mode.”
It’s under the Security tab - Now, click on Apply to apply these settings
- Click on OK to save this configuration
- After completing, close all the tabs there
- That’s it, done
By disabling the Enhanced Protected Mode from your Internet Explorer browser can get rid out of this Microsoft Visual Basic Runtime Error 438 vba excel code problem.
2. Install an Automatic Repair Tool on your Windows PC –
- Go & Search for Automatic Repair Tool on the Internet
- Download it from there
- Now, Click on ‘RUN‘ & Install it
- Open it and use the automatic repair tool
- After finish, close the tab
- That’s it, done
By installing an automated repair tool on your Windows PC will fix this Runtime Error 438 excel vba access problem quickly from you.
3. Uninstall Microsoft Works Add-in on your Windows PC –
- Click on the Start menu
- Search for Control Panel or directly open it
- Open ‘Add or Remove Programs‘ tab there
- Click on the file location in the options tab
- On the Uninstall/Install option,
- Select the Words in Works Suite Add-in
- Again, click on the Add or Remove Programs there
- Follow the ON Screen instructions
- After completing, close all the tabs from there
- Restart your PC
- Load the Microsoft Word again
- That’s it, done
By uninstalling the Microsoft Works Add-in can get back you from this type of excel Runtime Error 438 VBA code issue.
4. Use a Registry Cleaner to Clean the Registry of your Windows –
Clean your registry by any registry cleaner software so that it can fix and solve this VBA Runtime Error 438 object doesn’t support access problem from your PC completely.
5. Reinstall the Drivers for the Device on your PC –
By Reinstalling the drivers for the device will fix your Visual Basic outlook Runtime Error 438 fix problem.
6. Run a Full Scan of your Windows PC for Malware or Virus –
- Go to the start menu
- Search or go to the “Microsoft Security Essentials” there
- Click on it and opens it there
- A Pop-up will open there
- Check the ‘Full‘ option there to scan thoroughly
- After, click on the ‘Scan Now‘ option to scan carefully
- After scanning, close the tab
- That’s it, done
By running a full scan of your PC can get rid out of this Runtime Error 438 word Excel VBA problems from your PC completely.
7. Create a System Restore Point on your Windows PC –
- Go to the start menu
- Search or go to the ‘System Restore.’
- Clicks on it and open it there
- After that, tick on the “Recommended settings” or ‘Select a restore point‘ there
- After selecting, click on the Next option there
- Now, follow the wizard
- After completing, close the tab
- That’s it, done
So by applying this method on your Microsoft Windows PC can quickly solve this VBA Runtime Error 438 excel MAC issue.
“ OR “
- Go to the start menu
- Search or go to the ‘System Properties.’
- Click on it and opens it
- After that, go to the “System Protection” option there
- Now, click on the “System Restore” option there
- & Create a Restore point there
- After completing, close the tab
- That’s it, done
Run a system restore and creating a new restore point by any of these two methods can solve this Visual Basic Runtime Error 438 ecw excel mac problem from your PC completely.
8. Troubleshoot & Run an Automatic Windows Repair on your PC –
- Go to the start menu
- Search or go to the PC settings there
- Click on the ‘Troubleshoot‘ option there
- After opening, click on the ‘Advanced options‘ there
- Then, click on the “Automatic Repair” option there
- After troubleshooting, close the tab
- That’s it, done
By running an automatic repair of your PC can get rid out of this Microsoft Visual Basic excel vba Runtime Error 438 problem from your PC.
9. Disable or Uninstall your Windows Antivirus Software on your PC –
By Disabling or uninstalling your antivirus software can quickly fix and solve this Runtime Error 438 object doesn’t support this property or method epaceengagement problem.
10. Restart your Windows PC [OPTIONAL] –
- Go to the Start menu
- Click on the right side of ‘Shutdown.’
- Click on Restart option there to restart
- That’s it, done
If this is your first time you have seen this stop error screen then by restarting your PC again will quickly fix this Microsoft Visual Basic Runtime Error 438 VBA problem.
These are the quick and the best way methods to get quickly rid out of this Microsoft Visual Basic Runtime Error 438 VBA Windows PC Code problem from you entirely. Hope these solutions will surely help you to get back from this Microsoft Visual Basic Runtime Error 438 VBA issue.
If you are facing or falling in this Microsoft Visual Basic Runtime Error 438 VBA Windows PC Code problem or any error problem, then comment down the error problem below so that we can fix and solve it too by our top best quick methods guides.