Solved

Refernce to a field

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

Accepted Solution

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

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

Expert Comment

by:PatHartman
Comment Utility
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
Comment Utility
Thanks!
0
 
LVL 34

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now