Solved

Refernce to a field

Posted on 2014-02-05
4
291 Views
Last Modified: 2014-02-05
I am using the below code that is working great (thanks to your guys help). The issue is when it references the "Me.DateRecorded", it works if I have that actual field on the form. I would rather not have that in the field. The form is a subform of another that lists the DateRecorded. It is redundant (and space consuming) to have that value listed twice.

The value comes from a query titled "Booking Details Extended". The parent form that it is a subform of is titles "Bookings subform" (that is because it is still a subform to another main form). In essance, there are 3 levels of subforms.

Can I reference that date field without putting it on my actual form?



Private Sub ItemPrice_BeforeUpdate(Cancel As Integer)
Dim strCorrectPassword As String

strCorrectPassword = Abs(Me.BookNumber - 1111) * 2

If Me.DateRecorded < Date - 1 Then    'Reads in a date field on your from called "Some Date"
    If InputBox("Enter Password") <> strCorrectPassword Then 'Compares passwords
        Cancel = True
        MsgBox "Change not allowed without valid password.", vbOKOnly
        Me.ItemPrice.Undo 'undo recent change to this field
        Exit Sub
    End If
End If
End Sub
0
Comment
Question by:cansevin
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39836555
To refer to a control on a subform, use the following syntax:

Forms![main form name]![subform control name].Form![control name]
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39836672
Yes you can refer to a control on a subform using the syntax Macro suggested BUT, do you know what you are getting?

A form can have only a single current record and when you reference a control, you are referencing the value for the current record.  If the subform is continuous, it essentially contains many records and the one you will ALWAYS be referring to is the first record in the subform's RecordSource.  There is no way to refer to any other instance using this method.  You would need to manipulate the subform's RecordSource clone to move to any different instance.  If referencing only the first record works for you then your schema is probably incorrect and the date doesn't belong in that table but rather in a parent table.
0
 

Author Closing Comment

by:cansevin
ID: 39836914
Thanks!
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39837163
Perhaps once you have more than one record in the subform you'll understand the problem.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question