Solved

Refernce to a field

Posted on 2014-02-05
4
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 38

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 38

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

623 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