Solved

Refernce to a field

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

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 37

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

740 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