I am trying to complete an app to store donations for our church and print receipts. I have all the table built and related. Queries work and reports are fine. I am trying to apply receipt numbers to a receipts table that results from a query for donations. Table is fine. I have written VBA code to extract the last receipt number stored in the church table, number each of the records in the receipts table, then i will call the report to print the receipts. Following function works as it should when i run to cursor in debug, but when I try to call it from a button in the main menu form, I get an error that says that ChurchGivings can not find the function. I have tried runninf as code and have tried calling it from a macro. Same error every time. Can anyone help me solve this maddening problem? Function shows in modules and in the macro builder wizard. Public Function NumberReceipts() Dim TableName1, TableName2 As String Dim ChurchDB As Database, ChurchTable, ReceiptsTable As Recordset TableName1 = ““Church”” TableName2 = ““Receipts”” Set ChurchDB = CurrentDb() Set ChurchTable = ChurchDB.OpenRecordset(TableName1, dbOpenTable) Set ReceiptsTable = ChurchDB.OpenRecordset(TableName2, dbOpenTable) Do Until ReceiptsTable.EOF ReceiptsTable.Edit ReceiptsTable!ReceiptNumber = ChurchTable.[LastReceiptNumber] + 1 ReceiptsTable.Update 'Store the last receipt number ChurchTable.Edit ChurchTable.[LastReceiptNumber] = ReceiptsTable!ReceiptNumber ChurchTable.Update 'Now move on ReceiptsTable.MoveNext Loop 'Now clean up ChurchTable.Close ReceiptsTable.Close ChurchDB.Close End Function

Optimisticly, Thank You. Seems to work now. What a learning experience this has been. I had been developing with Paradox since the DOS days, but figured it was time to move on. MS has steamrollered it’s way into the majority of workplaces. I just retired this spring and thought this would be a good project :sunglasses:

Anyway, I moved a copy from my data drive to my desktop to make some final changes, not thinking that Windows feels that that should be protected space as it is only a folder in your user folder.
I also changed my module name, because I had them name the same as the functions. Tried everything and all seems to be working.

THANK YOU so much.
Have a HAPPY NEW YEAR!

Warren

Warren,

Based on my experience, sometimes it’s not a question of including the references but of moving the reference libraries up or down in the list of references. Have you experimented with changing the order that Access looks for the reference libraries?

Glenn J. Koster, Sr.
Eaton Hydraulics

Hi Warren,

Have you enabled Macros (on opening your database)? or placed your database in a trusted location?

Also, ensure that the function is defined public (hinted at in Michaels post) and missed in Abduls post…

Public Function ToEnglish(ByVal MyNumber)

Also, ensure that the module name doesn’t clash with the function name.

Regards

Nigel

Thanks. This gives the same result as my old one. Access cannot find any public functions even though they show in VBA editor project explorer.
Warren

I have used dBase, then Paradox since DOS days and am familiar with coding and programming, but this is so far out there that I am forced to search for help. I have attached three jpegs showing main Access window, VBA editor window and error I get when I click the Annual Receipts button on the main form to call the number function.

Hope you can come up some ideas.
Thanks,
Warren

Hi,

Try This Function
I hope this is helpful.

Option Compare Database
Option Explicit

Function ToEnglish(ByVal MyNumber)
Dim Temp
Dim Dirhams, Fils
Dim DecimalPlace, Count

ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "

’ Convert MyNumber to a string, trimming extra spaces.
MyNumber = Trim(str(MyNumber))

’ Find decimal place.
DecimalPlace = InStr(MyNumber, “.”)

’ If we find decimal place…
If DecimalPlace > 0 Then
’ Convert Fils
Temp = Left(Mid(MyNumber, DecimalPlace + 1) & “00”, 2)
Fils = ConvertTens(Temp)

’ Strip off Fils from remainder to convert.
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If

Count = 1
Do While MyNumber <> “”
’ Convert last 3 digits of MyNumber to English Dirhams.
Temp = ConvertHundreds(Right(MyNumber, 3))
If Temp <> “” Then Dirhams = Temp & Place(Count) & Dirhams
If Len(MyNumber) > 3 Then
’ Remove last 3 converted digits from MyNumber.
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = “”
End If
Count = Count + 1
Loop

’ Clean up Dirhams.
Select Case Dirhams
Case “”
Dirhams = “Zero Dirhams”
Case “One”
Dirhams = “One Dirhams”
Case Else
Dirhams = Dirhams & " Dirhams"
End Select

’ Clean up Fils.
Select Case Fils
Case “”
Fils = " And Zero Fils."
Case “One”
Fils = " And One Fils"
Case Else
Fils = " And " & Fils & " Fils."
End Select

ToEnglish = Dirhams & Fils
End Function

Private Function ConvertHundreds(ByVal MyNumber)
Dim Result As String

’ Exit if there is nothing to convert.
If Val(MyNumber) = 0 Then Exit Function

’ Append leading zeros to number.
MyNumber = Right(“000” & MyNumber, 3)

’ Do we have a hundreds place digit to convert?
If Left(MyNumber, 1) <> “0” Then
Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
End If

’ Do we have a tens place digit to convert?
If Mid(MyNumber, 2, 1) <> “0” Then
Result = Result & ConvertTens(Mid(MyNumber, 2))
Else
’ If not, then convert the ones place digit.
Result = Result & ConvertDigit(Mid(MyNumber, 3))
End If

ConvertHundreds = Trim(Result)
End Function

Private Function ConvertTens(ByVal MyTens)
Dim Result As String

’ Is value between 10 and 19?
If Val(Left(MyTens, 1)) = 1 Then
Select Case Val(MyTens)
Case 10: Result = “Ten”
Case 11: Result = “Eleven”
Case 12: Result = “Twelve”
Case 13: Result = “Thirteen”
Case 14: Result = “Fourteen”
Case 15: Result = “Fifteen”
Case 16: Result = “Sixteen”
Case 17: Result = “Seventeen”
Case 18: Result = “Eighteen”
Case 19: Result = “Nineteen”
Case Else
End Select
Else
’ … otherwise it’s between 20 and 99.
Select Case Val(Left(MyTens, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select

’ Convert ones place digit.
Result = Result & ConvertDigit(Right(MyTens, 1))
End If

ConvertTens = Result
End Function

Private Function ConvertDigit(ByVal MyDigit)
Select Case Val(MyDigit)
Case 1: ConvertDigit = “One”
Case 2: ConvertDigit = “Two”
Case 3: ConvertDigit = “Three”
Case 4: ConvertDigit = “Four”
Case 5: ConvertDigit = “Five”
Case 6: ConvertDigit = “Six”
Case 7: ConvertDigit = “Seven”
Case 8: ConvertDigit = “Eight”
Case 9: ConvertDigit = “Nine”
Case Else: ConvertDigit = “”
End Select
End Function

Warren,

I am somewhat at a loss how to help you. While it is always a challenge to learn to work with a new programming environment, your experience is way beyond the normal level of frustration. However, I am still having trouble interpreting what you are reporting - it seems as though we are describing things in very different terms.

At this point, all I can think of to do is to try to provide a detailed description of what the Microsoft Access 2010 Visual Basic Window looks like, and how it behaves.

To begin with, the Visual Basic Window has a title bar, a menu bar, a tool bar, and one or more panes. Typically, there are four panes:
The main pane, which is on the right hand side, extending from the tool bar down, is the Code Pane. This will display the contents of one, and only one of the code modules.
Below the Code Pane is the Immediate window. You can type VBA statements in this window for immediate execution. When you are debugging, the statements can include variables that are in scope.
On the top left of the main window is the Project Explorer. More about that in a bit.
Below the Project Explorer is the Properties Window, which will display the properties of a selected object.

The Project Explorer displays a tree view of the current project (that is, the database) and the modules it contains. At the very top (the root of the tree) you should see the name of the current database, in bold. Below that you will see the rest of the tree.

Normally, the first level of branches will have two or three folders:
Microsoft Access Class Objects - all the modules that are associated with Forms, Reports, etc.
Modules - all the independent modules
Class Modules - all the class modules that are created to hold user-defined objects (if any)

However, there is an icon on the Project Explorer’s tool bar that can Toggle Folders, which removes this level of the tree, so that all the modules will be listed as direct children of the root.

Either way, it is important to remember that the Code Pane shows the contents of a single module from the tree (unless you click the Maximize button - the Code Pane is maximized by default - in which case you can see multiple code panes in the window, with each code pane displaying the code from a single module).

From your descriptions of the problems you have had, it seems likely that you have not understood the significance of having multiple modules, or the fact that the Code Pane displays only one module.

Now, what does it mean to have multiple modules? It is absolutely vital to distinguish between associated modules and independent modules. All of the code that is associated with a form must be in that form’s associated module. The event procedures that you create to respond to button clicks or to validate entered data must be in the form’s module. On the other hand, global procedures - procedures that you want to be able to use from different parts of the database - procedures that you want to call from multiple forms or reports - must be in independent modules.

Open your database, and open the Visual Basic Window. Look at the Project Explorer. You should see two modules under the first folder - one for each of the two data entry forms you created (if you have not added any code to a form, you won’t see an entry for that form). You can view the code for either module by double-clicking the module name in the Project Explorer.

Below those modules, you should see the folder for Modules. If you have inserted a module, it will appear under that folder, and you can double-click its name to view the code it contains. This is where global procedures must appear. In particular, your English() function, and your NumberReceipts() function, should appear.

Michael S. Meyers-Jouan

I rebuilt the tables and relationships. Recreated three functions, all public. Built two forms for data entry and they works. I have a function called English that I found on line to display a number as written text. When I first downloaded it about a month ago, it worked. I placed an unbound text box on a form and used the expression builder to build =English(123.45) to call it and all I get is #Name? error in the box.

When I open the VBA editor, all I see are the functions. In the previous attempts, I have been able to see all the forms and reports that I have created and mistakenly attached code to them instead of the database. Trying to get this to work.

I have a piece of VBA code that renumbers receipts from the last receipt number that I have stored in the company info table. When I built it, it compiled and worked fine, but I had mistakenly embedded it into one of the forms I had built and it worked there. After I moved it to a public location, I could not use it anywhere.

I have even gone to the last straw of reinstalling the MS Office 2010.

Trying not to be a nuisance about this, just trying to learn MS way of programming.

Warren

Warren,

I’m confused. You just created a new database, and now you can’t see any forms or functions in the VBA Project Explorer.

If you have created a new database, WHY WOULD YOU EXPECT TO SEE ANYTHING THERE?

You do realize that the Project Explorer displays the contents of the currently open database, don’t you?

You cannot use functions that you created in one database from another database. You must copy the functions into each database where you want to use them.

Michael S. Meyers-Jouan

I once wrote a function and named it PAYE and also named the module PAYE. I almost became mad. It could work in debug.print but else where nop.

Check the naming of your function and module.

Ronald

Just built totally new database and now I can not see any forms in VBA project viewer and no functions can be seen.

Totally frustrated with Access. Thought this would be a great learning project. Some forms/reports show in project viewer, some don’t. Access will not find any custom functions. I have learned how to distinguish between imbedded functions and public functions.

With nothing opened but the database and the module in design mode, The function is stored in module one level below database. Is this the correct placement?
Thanks

Warren,

The most likely cause is that your function NumberReceipts() is in an associated module, rather than an independent module.

One of the panes in the Visual Basic Window is the Project Explorer. It is usually at the top left corner of the window. The Project Explorer displays a tree view that contains all the modules in the current database. The modules are in three major divisions:
Microsoft Access Classes - the modules that are associated with objects such as forms and reports
Modules - the independent modules that are not associated with anything else (these are typically created using the Insert, Module menu command)
Class Modules - modules that contain “object oriented” classes that can be used like the built-in objects

Procedures that you create in the associated modules cannot be referenced simply by name. If they are Public, you can call them from outside the module, but you must include the module name (object name) as a prefix to the procedure name.

Procedures that you create in independent modules (and declare Public) can be called from anywhere. They are effectively “global” procedures.