473,425 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Me.field is not recognized

3
I made a form using the wizard which named my text boxes the same name as their control source (RollDate1, RollDate2). After adding code to be run when the use clicks a button, I went back and changed them to txtRollDate1, txtRollDate2 and unbound them. Here is what is supposed to happen when they click the OK button.

Me.RollDate1 = Me.txtRollDate1.Value
Me.RollDate2 = Me.txtRollDate2.Value

The problem is that the coding is not recognizing the Me.RollDate as a field in the table. (I get a "Method or Data Member Not Found" error message) It is working fine for other fields, but not these two. Any suggestions? (My reasoning behind doing this is so that when a user 'accidentally' closes out the form, it doesn't enter false data into the table. Any help would be appreciated. Thanks in advance!
Aug 28 '07 #1
7 11064
Scott Price
1,384 Expert 1GB
I made a form using the wizard which named my text boxes the same name as their control source (RollDate1, RollDate2). After adding code to be run when the use clicks a button, I went back and changed them to txtRollDate1, txtRollDate2 and unbound them. Here is what is supposed to happen when they click the OK button.

Me.RollDate1 = Me.txtRollDate1.Value
Me.RollDate2 = Me.txtRollDate2.Value

The problem is that the coding is not recognizing the Me.RollDate as a field in the table. (I get a "Method or Data Member Not Found" error message) It is working fine for other fields, but not these two. Any suggestions? (My reasoning behind doing this is so that when a user 'accidentally' closes out the form, it doesn't enter false data into the table. Any help would be appreciated. Thanks in advance!
Me.[FieldName] is the method of referring to a control on a form, not a field in a table. So when you renamed the control to txtRollDate1, there no longer exists a control named RollDate1 on your form, and therefore the db cannot find that Data Member.

As for the larger picture, I'm not sure how your reasoning is actually going to work for what you state as the objective. In any case, data validation is better handled in the BeforeUpdate event of the form, where the update can be canceled before the incorrect data is written to the table. Also, if you simply refer a control to itself, the data will still be saved with an 'accidental' closure of the form (I'm not sure if that situation is all that common, either?! )

Regards,
Scott
Aug 28 '07 #2
bane
3
Me.[FieldName] is the method of referring to a control on a form, not a field in a table. So when you renamed the control to txtRollDate1, there no longer exists a control named RollDate1 on your form, and therefore the db cannot find that Data Member.

As for the larger picture, I'm not sure how your reasoning is actually going to work for what you state as the objective. In any case, data validation is better handled in the BeforeUpdate event of the form, where the update can be canceled before the incorrect data is written to the table. Also, if you simply refer a control to itself, the data will still be saved with an 'accidental' closure of the form (I'm not sure if that situation is all that common, either?! )

Regards,
Scott
I'm a little confused. In the many other instances where I have use Me.[FieldName] to refer to a field in a table, it works the way I want it to. The problem lies in that the text field in the form was originally the same name as the field in the table (thank the wizard for that). I also just noticed that the Properties/Methods list doesn't show the new fields that I put in the table. FYI, the Properties/Methods list shows every field in my table (minus the new fields) along with every field in the form.
A bit more explanation on my reasoning - If the form fields are bound to the table and an user puts in a wrong value then closes the form, that wrong value is stored in that field in the table. And depending on which value they enter, it may prevent that record from being accessible by that form again (due to queries being run on opening, etc). So by making the form fields unbound, the only way that information gets to the table is via the code that I am trying to get to run via them hitting the OK button.
If that still does not make sense, let me know and I will try to explain further.
(BTW, I am using Access 2003 and VB 6.5)
Aug 28 '07 #3
Scott Price
1,384 Expert 1GB
I'm a little confused. In the many other instances where I have use Me.[FieldName] to refer to a field in a table, it works the way I want it to. The problem lies in that the text field in the form was originally the same name as the field in the table (thank the wizard for that). I also just noticed that the Properties/Methods list doesn't show the new fields that I put in the table. FYI, the Properties/Methods list shows every field in my table (minus the new fields) along with every field in the form.
A bit more explanation on my reasoning - If the form fields are bound to the table and an user puts in a wrong value then closes the form, that wrong value is stored in that field in the table. And depending on which value they enter, it may prevent that record from being accessible by that form again (due to queries being run on opening, etc). So by making the form fields unbound, the only way that information gets to the table is via the code that I am trying to get to run via them hitting the OK button.
If that still does not make sense, let me know and I will try to explain further.
(BTW, I am using Access 2003 and VB 6.5)
I understand what you are saying, however, if you read carefully my earlier post, and if you would explore carefully the other situations, I think you will find that Me.[FieldName] is referring to a control on the form, not directly to the field in the table.

What happens is that the Me keyword in access vba refers to the collection of the currently executing code block. So if you are using this in the code module of a form, it will only refer to controls on the form.

You should look into an update query (i.e. INSERT INTO) to do what you are trying to accomplish. You can run this from vba using the DoCmd.RunSQL command. Access's help file is actually quite helpful to point out the syntax of these two methods.

Good luck!

Regards,
Scott
Aug 28 '07 #4
Ok, 9 years too late but I've found a pretty ugly workaround for this one Bane.

Add a new combobox on your form and set your Dlookup to autopopulate this new control on the form, as Scott mentions. Then, once it is working, you can delete the control from the form and the Dlookup will continue to work in VBA.

An inelegant solution but it got me out of a hole so hopefully it can help someone else.
May 25 '16 #5
PhilOfWalton
1,430 Expert 1GB
Apart from anything else Me.ControlName is OK
Me.FieldName is not.
Forms & Reports have controls, not Fields

Phil
May 25 '16 #6
Seth Schrock
2,965 Expert 2GB
Me!Field_Name is acceptable however. I use it all the time.
May 25 '16 #7
NeoPa
32,556 Expert Mod 16PB
@Juddles.
I find an easier solution is to add bound controls to your form that are not visible and reference them instead. I actually have hidden sections for just that purpose on some forms.

Yes. The items you see on forms and reports are controls and not fields, however forms and reports do still have fields related to their Record Sources. These can be referenced from VBA, as Seth indicates. I'm not so sure about accessing them from within other controls on the form though, except where using Aggregate functions like Sum(), Max(), etc.
May 26 '16 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: compusup3000 | last post by:
Hi, I have an orders database and I need to be able to write a query that groups sales by: 1. Date 2. Time of day (both am and pm) I currently have a date/time field named "Submitted" that...
3
by: Fran Zablocki | last post by:
I have a process that exports an Access table to a comma-delimited text file. One of the fields that is exported shows the date it was exported, using the Date() function. In the Access table, the...
2
by: Tony Johnson | last post by:
Hello, I have a form that has a lot of fields. It is based on a one table. I have company information and then a description. I have to continually type in the description and it is a...
19
by: cover | last post by:
Is there a restriction to the number of fields you can work with in a PHP to MySQL connection? I'd used as many as 15 quite a few times and now I have a form with 34 fields and can't seem to get...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
2
by: John | last post by:
Hi Everyone, I have a question about dynamically changing the length of a varchar(n) field, in case the value I'm trying to insert is too big and will give a "truncated" error, but before the...
2
by: ruthiefy | last post by:
Hi, I need a few sql queries results so I created a new class with has a few functions that load the data. After executing ExecuteReader, I need to load the data to the dropdownlist control....
3
by: myemail.an | last post by:
If I need to format how the content of a field is displayed, I can click ALT + ENTER from design view, and specify the format, for example, the number of decimal digits and so on. Is there a way...
0
by: fantasticamir | last post by:
I have a simple program using a couple of classes and it compiled successfully but while it is linking I have the following problem: g++ -Wall -lcu -lglu ACL2MDD.o Link.o Rule.o reachability.o ...
5
by: hassanhundal007 | last post by:
In my table the field of DateTime name is TIN. In this field DATE and TIME are shown for date I pass this query: SELECT DAY(TIN) FROM SHIFT WHERE SHID = 1 Then the result is "10". So the same I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.