VBA Causing Disruption on controls (1 Viewer)

mickmullen

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 30, 2018
Messages
19
Newbie here, I'm having a problem trying to implement VBA.



I have a Form that is working fine, then I turn on the VBA and some controls stop working.


For example, I have a text box control source set to this


=DLookUp("[Project Name]","ProjectLog","[Project Number] =" & [Forms]![WorkOrders]![Project Number])


works great until I try to put some code on a button on the same form. Now I get a popup asking for [Forms]![WorkOrders]![Project Number] entry


I feel like I'm missing a basic concept, or a setting is wrong. Any suggestions are much appreciated.


Mick
 

NauticalGent

Ignore List Poster Boy
Local time
Yesterday, 21:58
Joined
Apr 27, 2015
Messages
6,328
Can you post the code attached to the button?
 

mickmullen

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 30, 2018
Messages
19
I dont have anything yet.. Just says Option Compare database


The VBA explorer says i'm in



"Microsoft Office Class Objects" folder
-Form_WorkOrders
 

NauticalGent

Ignore List Poster Boy
Local time
Yesterday, 21:58
Joined
Apr 27, 2015
Messages
6,328
[Shooting from the hip, i think the problem lies with trying to do a DLookup thst involves a textbox value that is null. Try replacing
Code:
" & [Forms]![WorkOrders]![Project Number])

With
Code:
" & Nz([Forms]![WorkOrders]![Project Number]))
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:58
Joined
Feb 28, 2001
Messages
27,167
Now I get a popup asking for [Forms]![WorkOrders]![Project Number] entry

Invariably, this popup message occurs when Access cannot find the thing that it is asking you to enter. The reasons can vary, but...

#1 reason is spelling, i.e. the thing you named isn't exactly spelled that way.

#2 reason is (since you referenced the [Forms] collection) that the item in question is on a form that isn't open at the time. If the control that you want to read is on the same form as the event you are trying to debug, then consider this:

If you are running code in an event fired from [Forms]![WorkOrders] then instead of using a long-winded reference to [Forms]![WorkOrders]![Project Number], use Me![Project Number] as a shorter way to get to that control. If the event is NOT from that form, though, then you will need the long-winded reference. Also, ...


works great until I try to put some code on a button on the same form

Can you describe the steps you used to put code on a button?
 
Last edited:

mickmullen

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 30, 2018
Messages
19
I have the same scenario in another Form, except everything is working fine.

The problem form works fine too, until that forms Module property is turned on. Then it doesn't work.



Heres the setup
On the a form named "EstimateDataReportForm"
Combo box selecting project number (to a table with number and name fields)
- text box with
=DLookUp("[Project Name]","ProjectLog","[Project Number] =" & [Forms]![EstimateDataReportForm]![Project Number])
And I have unrelated buttons that are running code on the same form
This form works as intended, whether the Module property is on or off
 

GinaWhipp

AWF VIP
Local time
Yesterday, 21:58
Joined
Jun 21, 2011
Messages
5,899
The Module has nothing to do with it if there is no code in it. I would suggest you study Doc_Man's reply as it looks to apply to this Form as well.
 

mickmullen

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 30, 2018
Messages
19
FYI- I've created a copy of the problem form and everything works as expected.


I must have changed some setting in the VBA or something.


Not really solved, as I don't know why the program was behaving like that, but I can at least move on
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:58
Joined
Sep 21, 2011
Messages
14,260
FWIW, if the control you are searching on is on the same form, you do not need the form reference
One of mine
Code:
=DSum("Amount","Emails","CMS = " & [CMS] & " AND ID <=" & [ID])
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:58
Joined
Feb 28, 2001
Messages
27,167
whether the Module property is on or off

If the form works as intended when the Module property is set to NO then your problem has nothing to do with modules at all. It HAS to have been a setting. I see in a follow-up post that it is now behaving.

The greatest strength and greatest frustration is that Access lets you see EVERY FRIMPIN' PROPERTY on EVERY STINKIN' CONTROL and sometimes the properties interact in strange ways. Therefore I cannot fault your guess that something was set wrong. But you said that it started behaving better when you made a copy of the form. That implies a new form class module, which means if the OLD form was giving you issues, that you had some form of corruption in there, probably from some of your experiments of trying to make something work.

FYI, a form's HasModule property is not really one of those things you want to adjust. It is one that Access will adjust FOR you based on whether you have defined code in the class module or not. For you to muck with the HasModule property is doing things in the wrong order for that particular property.

Sometimes, that is NOT the case. But for the .HasModule property, just don't play with that. It is an indicator of the existence of something, not a dynamic status flag.
 

Users who are viewing this thread

Top Bottom