Hello,
I am trying to refer to fields on a given form from the form query's recordset, essentially from the following commands: -
Dim frm As Form 'Refers to the current form
-
Dim tagName As String 'Refers to the field in the form's recordset (not a control on the form)
-
-
...
-
frm.Fields(tagName).Value 'This gives Error 2465
-
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: -
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
-
Dim keyName As String, keyValue As Long
-
Dim tempRecord As Long
-
Dim fld As Field
-
-
On Error GoTo Err_duplicateRecord
-
Set rsExist = CurrentDb.OpenRecordset(tableName)
-
keyName = uniqueCtl.ControlSource
-
If uniqueCtl.Value > 1 Then
-
keyValue = uniqueCtl.Value
-
If frm.NewRecord Then
-
Call MsgBox("New records cannot be duplicated, please save this record first then try again.", vbExclamation, "Nonexistant Record")
-
duplicateRecord = -1
-
Exit Function
-
ElseIf frm.Dirty Then
-
If MsgBox("Save changes?", vbYesNo, "Unsaved Changes Detected") = vbYes Then
-
MsgBox frm.Fields("LineTag")
-
If isSaveable(tableName, tagName, frm.Fields(tagName).Value, keyName, keyValue) Then 'This gives Error 2465
-
Call saveRecord(frm, keyValue)
-
Else
-
Exit Function
-
End If
-
Else
-
Exit Function
-
End If
-
End If
-
...
-
End Function
-
Just figured it out, I used:
frm.RecordSet.Fields(tagName)
Thanks for help ADezii, Me.RecordsetClone was a good hint.
3 3980
I'm actually a little confused about your question, but to Output a List of Fields comprising a Form's Recordset: - Dim rst As DAO.Recordset
-
Dim fld As DAO.Field
-
-
Set rst = Me.RecordsetClone
-
-
For Each fld In rst.Fields
-
Debug.Print fld.Name
-
Next
Sample Output: - EmployeeID
-
LastName
-
FirstName
-
MI
-
Title
-
TitleOfCourtesy
-
BirthDate
-
HireDate
-
Address
-
City
-
Region
-
PostalCode
-
Country
-
HomePhone
-
Extension
-
Photo
-
Notes
-
ReportsTo
To actually refer to Fields within the context of a Form's Recordset, once it has been defined: - rst!EmployeeID
-
rst!LastName
-
rst!FirstName
-
rst!MI
-
rst!Title
-
rst!TitleOfCourtesy
-
rst!BirthDate
-
rst!HireDate
-
rst!Address
-
rst!City
-
rst!Region
-
rst!PostalCode
-
rst!Country
-
rst!HomePhone
-
rst!Extension
-
rst!Photo
-
rst!Notes
-
rst!ReportsTo
Just figured it out, I used:
frm.RecordSet.Fields(tagName)
Thanks for help ADezii, Me.RecordsetClone was a good hint.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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()...
|
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.
...
|
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>
...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |