Solved

Refernce to a field

Posted on 2014-02-05
4
290 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

821 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