COMPILE ERROR (MS-Access)

Occasional Reader

Hello All,

 

I am fairly new to programming our MS-Access Database, i have built a tool/button to allow my users to click and it opens a new email from their outlook.  I am trying to get a very specific subject line to carry over our project number & what we call out project label/name.  I keep getting this "Compile Error: Method or data member not found" and can not seem to figure out what i have wrong in the code or why it wont find the project label that is in the database. Im sure this is something simple i am just missing

 

kevin675_0-1727874404532.png

12 Replies

Hi,

 

There are some ambiguities in your description. You write

> the project label that is in the database

 

1. What is "CurrentProjectName"? A field name or a control name or both? If a control, then which kind of control? A label control wouldn't have a "Value" property.


2. "in the database" is not enough. Since you are referencing it with Me, it must be in the same object (or its data source) as the code. If that's the case then:

In which kind of Access object are "CurrentProjectName" and the code? A form or a report?

 

Depending on your answers to all these questions, it could help to use Me! instead of Me.

 

Servus
Karl
****************

Access Forever News DevCon
Access-Entwickler-Konferenz AEK - 19./20.10. Nürnberg

@Karl_Donaubauer 

 

Thank you for your reply, i am trying to pull the data from this field:

kevin675_0-1727878289279.pngkevin675_1-1727878307646.pngkevin675_2-1727878320916.png

kevin675_3-1727878336724.png


For Some reason, it works on another button we have which is where i snagged the code from, but when i add that same code to the new button is when im getting the COMPILE ERROR

 

This Button pulls the data im needing without an issue

kevin675_4-1727878409911.png

using this code, it works fine for the button above but not the new button i created

Private Sub cmdCopytoEmail_Click()
Dim ol As New Outlook.Application
Dim MI As MailItem
Set MI = ol.CreateItem(olMailItem)
MI.Subject = "Proj #" & Me.ID.Value & "-" & Me.Project_Name.Value
MI.BodyFormat = olFormatHTML
MI.Display
Set MI = Nothing
Set ol = Nothing
End Sub

 

Hi,

 

The property sheet shows that the text box + field name contain a space. Therefore you have to put it in square brackets in VBA:  Me.[Project Name].Value

 

Servus
Karl
****************

Access Forever News DevCon
Access-Entwickler-Konferenz AEK - 19./20.10. Nürnberg

@Karl_Donaubauer   Thank you, I seem to still have something wrong, I added the square brackets and I get the following:

kevin675_0-1727879584364.png

kevin675_1-1727879593563.png

 

Is the correct name of the control./field "Project Name", or "Current Project Name"?
George, the correct name of the control box is "Project Name" for some reason, when i try to use that in the code it wont find that specific control box
But that is not the name shown in your screenshot, is it? Doesn't the yellow highlighted line in the screenshot show Me.[CurrentProjectName] ?
I changed it to "Current" project name after the previous suggestion on how to fix my error problem, the Control Box is actual "ProjectName"
But if there is no such field and no such control, it's wrong to call it "CurrentProjectName". Access is quite literal. If you tell it "use this name", it will look only for that name and nothing else. Whatever else is going on, the code needs to refer only to control and field names that exist.

@George_Hepworth 

 

Here is what the control box is called for the project name:

kevin675_0-1727907082336.png

Here is the code with the error message

kevin675_1-1727907137268.png


Im sure it is something really basic im missing and just not seeing or finding it.  I appreciate all your advice so far

 

@kevin675 

Thank you. I think this was mentioned in a previous response.
Your code reference is Project_Name with an underscore, which is not the same as [Project Name].

Try replacing Project_Name in the code  with [Project Name]

 

Also, a reminder. This kind of fiddly name stuff is why most professional and experienced Access developers do not use object names with spaces in them. It gets slippery when trying to track down errors like this. 

@George_Hepworth 

Thank you for the advice and note about the object names with spaces, i will for sure keep that in mind moving forward.  I tried your suggestion with replacing it with [Project Name] and I now get a Runtime Error code

kevin675_1-1727915643491.png

 

kevin675_0-1727915635169.png