473,394 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Reference Form Fields Value - Application-defined Error 2465

Hello,

I am trying to refer to fields on a given form from the form query's recordset, essentially from the following commands:
Expand|Select|Wrap|Line Numbers
  1.     Dim frm As Form 'Refers to the current form
  2.     Dim tagName As String 'Refers to the field in the form's recordset (not a control on the form)
  3.  
  4.     ...
  5.     frm.Fields(tagName).Value 'This gives Error 2465
  6.  
My question is how do I refer to a field in the form's record set (not an individual control on the form)? If I use frm![LineTag].Value, it works fine, but frm.Fields(tagName).Value does not. Conversely, rs.Fields(tagName) does work fine. (note: tagName="LineTag")

Please let me know how I can refer to a form's recordset field.

Thanks!

...
For more info and as to why I need it, here is a large chunk of the function I use to call the segments mentioned above:
Expand|Select|Wrap|Line Numbers
  1. Function duplicateRecord(ByRef frm As Form, tableName As String, uniqueCtl As TextBox, tagName As String, ByRef avarExceptionList() As String) As Long     Dim rsExist As Recordset
  2.     Dim keyName As String, keyValue As Long
  3.     Dim tempRecord As Long
  4.     Dim fld As Field
  5.  
  6. On Error GoTo Err_duplicateRecord
  7.     Set rsExist = CurrentDb.OpenRecordset(tableName)
  8.     keyName = uniqueCtl.ControlSource
  9.     If uniqueCtl.Value > 1 Then
  10.         keyValue = uniqueCtl.Value
  11.         If frm.NewRecord Then
  12.             Call MsgBox("New records cannot be duplicated, please save this record first then try again.", vbExclamation, "Nonexistant Record")
  13.             duplicateRecord = -1
  14.             Exit Function
  15.         ElseIf frm.Dirty Then  
  16.             If MsgBox("Save changes?", vbYesNo, "Unsaved Changes Detected") = vbYes Then
  17.                 MsgBox frm.Fields("LineTag")  
  18.                 If isSaveable(tableName, tagName, frm.Fields(tagName).Value, keyName, keyValue) Then 'This gives Error 2465  
  19.                     Call saveRecord(frm, keyValue)  
  20.                 Else
  21.                     Exit Function
  22.                 End If
  23.             Else
  24.                 Exit Function
  25.             End If
  26.         End If
  27.     ...
  28. End Function
  29.  
Oct 29 '10 #1

✓ answered by jbrumbau

Just figured it out, I used:
frm.RecordSet.Fields(tagName)

Thanks for help ADezii, Me.RecordsetClone was a good hint.

3 3980
ADezii
8,834 Expert 8TB
I'm actually a little confused about your question, but to Output a List of Fields comprising a Form's Recordset:
Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim fld As DAO.Field
  3.  
  4. Set rst = Me.RecordsetClone
  5.  
  6. For Each fld In rst.Fields
  7.   Debug.Print fld.Name
  8. Next
Sample Output:
Expand|Select|Wrap|Line Numbers
  1. EmployeeID
  2. LastName
  3. FirstName
  4. MI
  5. Title
  6. TitleOfCourtesy
  7. BirthDate
  8. HireDate
  9. Address
  10. City
  11. Region
  12. PostalCode
  13. Country
  14. HomePhone
  15. Extension
  16. Photo
  17. Notes
  18. ReportsTo
To actually refer to Fields within the context of a Form's Recordset, once it has been defined:
Expand|Select|Wrap|Line Numbers
  1. rst!EmployeeID
  2. rst!LastName
  3. rst!FirstName
  4. rst!MI
  5. rst!Title
  6. rst!TitleOfCourtesy
  7. rst!BirthDate
  8. rst!HireDate
  9. rst!Address
  10. rst!City
  11. rst!Region
  12. rst!PostalCode
  13. rst!Country
  14. rst!HomePhone
  15. rst!Extension
  16. rst!Photo
  17. rst!Notes
  18. rst!ReportsTo
Oct 29 '10 #2
Just figured it out, I used:
frm.RecordSet.Fields(tagName)

Thanks for help ADezii, Me.RecordsetClone was a good hint.
Oct 29 '10 #3
ADezii
8,834 Expert 8TB
It is usually a good idea to always avoid accessing the actual Form's Recordset in any manner, which is why I always use RecordsetClone whenever appropriate.
Oct 29 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
4
by: karenmiddleol | last post by:
I have the following form the user enters the From and to period and presses the Submit button and the form fields are cleared once the submit button is pressed. Is there a way I can keep the...
3
by: Li Zhang | last post by:
I know I can use controlName.Value to retrieve the form fields value if I am in that page. But if I am out of the page, for example I am in a HttpModule, I want to retrieve a hidden filed value, Is...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
7
by: Perks | last post by:
Hi. I am trying to find out if it is possible to open a pdf file from within PHP, and parse its contents in order to extract all form fieldnames that might have been previously setup within the...
3
by: guido | last post by:
I've written a user control to add form fields to a aspx page: Private Sub buildFields() 'Label1.Text = "building fields at " & System.DateTime.Now() Dim themeIDField As New TextBox()...
1
by: magmike | last post by:
Looking to do sort of the same thing you see on websites, but on access form, where when a value is selected from a drop down list, if it matches the desired value, certain form fields appear. ...
1
by: AR123 | last post by:
Hi I have set up mandatory form fields but it dosne t seem to be working. Would appreciate it if somone could have a look. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> ...
1
by: ERobishaw | last post by:
Using Winform app writing a HTTP Post using the following... on the server side, I get no form fields. Request.Form.AllKeys.Length = 0. If I put the field/value paris in the URL I can use...
0
by: =?Utf-8?B?YnJ1Y2UgYmFya2Vy?= | last post by:
asp.net munges the name, because this is what the browser posts. remember forms can not be nested, so the placeholder must be outside the form. you could create you own naming container, that did...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.