I have a table as below in test.mdb Access database. on a form, I want to use lookup to capture the the last field name in a text on the form, in this case, it is 200906.
by using some code I searched on the web site, I only can see all the field names, How can I just capture the last field name in the crosstab query.
Thanks, SunnyC -
LocationNo Customer No Status 20090101 20090201 20090301 20090401 20090501 20090601
-
34 1018 Active 1 1 1 1
-
28 1038 Active 84 41 39 31 15
-
21 1035 Active 14 11 6 3 1
14 11906 Frinavale 9,735
Recognized Expert Moderator Expert
Hi SunnyC!
Welcome to Bytes :)
You can find answers and ask Access questions in the Access Answers Forum.
Are you using SQL to access the lookup table?
If so could you please post it so that we can see what you're doing?
-Frinny
I searched the web and got the code for my report, but since I am a beginner. need help on how to capture the last field name and show it on a text box on a form.
here is my code: -
Sub Test()
-
Dim Cn As ADODB.Connection
-
Dim CrossTbl As ADODB.Recordset
-
Dim fld As Field
-
Set Cn = New ADODB.Connection
-
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\SunnyC\Desktop\Test.mdb;"
-
Cn.Open
-
Set CorssTbl = New ADODB.Recordset
-
-
CrossTbl.Open "TheReport", Cn
-
-
For Each fld In db.Recordsets("TheReport").Fields
-
Debug.Print fld.Name
-
Next fld
-
MyTable.Close
-
MyConn1.Close
-
End Sub
Thank you for the help,
SunnyC
Frinavale 9,735
Recognized Expert Moderator Expert
That looks like VB (6) code.
Are you programming a VB6 Application or an Access application?
Do you know how to use SQL to retrieve information from a database?
I don't see where you've declared your variable "db".
ChipR 1,287
Recognized Expert Top Contributor
Here's some very crude code (that uses late binding instead of reference dependencies): - Dim strLastField As String
-
Dim db As Object
-
Dim fld As Object
-
Dim intFieldCount As Integer
-
-
Set db = CurrentDb
-
-
'loop through all the fields to count how many there are
-
intFieldCount = 0
-
For Each fld In db.TableDefs("NameOfYourTable").Fields
-
intFieldCount = intFieldCount + 1
-
Next fld
-
-
If intFieldCount > 0
-
strLastField = db.TableDefs("NameOfYourTable").Fields(intFieldCount - 1).Name
-
End If
I am using Access Application. I know little of SQL, do not know how to use it retrieve information form a database. can you show me how?
thanks.
Frinavale 9,735
Recognized Expert Moderator Expert
I'm sorry but I don't know much about Access (I'm mainly a .NET developer). I never knew how close the Access syntax was to VB6.
Anyways, it's always useful to know SQL (it stands for: Structured Query Language and is pronounced See-quill). SQL lets you specify what you're looking for....the database management system (in your case Access) reads the SQL you provide to it, compiles it into a command and returns any records that match what you've asked for.
For example, if you were looking for a record with the Field (named ID) with the value of 200906 you would have something like:
SELECT * FROM test WHERE id = 200906;
This statement will retrieve all of the fields (*) for any records that have a value of 200906 in the "id" field from the table named "test". w3cschools is a great place to learn SQL.
Just be aware that SQL is always a little different for every database management system. It's supposed to be a standard so learning from w3cschools is a great idea but Access will have it's own twist on its SQL.
I should probably let the Access experts take over now :)
-Frinny
PS you may want to let the experts here know what version of Access you're using.
Thank you very much Frinny for the information and suggestions. I will take a look of it!
SunnyC
NeoPa 32,569
Recognized Expert Moderator MVP
You refer to the data source in one sentence as a table, but in another as a CrossTab query.
Any solution will need to follow a better understanding of what you require to be appropriate. If you can share that with us I'm sure we can help you.
Welcome to Bytes!
hey! I'm super new too... let me see if I can help... Assuming
1)the name of the query/table you are referring too is "MyTable"
2)you have an AutoNumber field in the query/table called "PrimKey" (you could also refer to any date field in the table or anything that has the create date of the record)
3) create a reference to "Microsoft Access 10.0 Object Library"
4) your textbox is called "TextBox1"
paste this code to the OnClick event of a button on your form: - Dim Con As ADODB.Connection
-
Set Con = CurrentProject.Connection
-
Dim rs As New ADODB.Recordset
-
Dim sql As String
-
sql = "select * from MyTable order by PrimKey desc"
-
With rs
-
.ActiveConnection = Con
-
.Open (sql)
-
End With
-
-
Textbox1.text = rs.fields("locationNo").Value
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: my-wings |
last post by:
I've been reading about how evil Lookup fields in tables are, but I've got
to be missing something really basic. I know this subject has been covered
before, because I've just spent an hour or two reading about it on google,
but there is something I still don't understand, and I'm hoping someone will
be willing to explain it to me in small words.
Let's say I have a table for addresses, and it includes a field for state.
What I would...
|
by: Zachary Turner |
last post by:
I want to make a Lookup Field based on another Lookup field. In other
words, I have this table A with two fields: ID and Name, where ID is
an Autonumber and Name is a friendly name. Then I have a table B
which links to A via a Lookup Field so that I can select the friendly
name from combo box. Now, I want to have a table C which links to
table B via a lookup field, and only displays the items which are
selected in some combo box of some...
|
by: John Baker |
last post by:
Hi:
I have a general question about table access and look ups.
Over simplifying things,and using a very theoretical example, lets say I have two tables;
Client and Bill.
The client table has a unique auto number (which is indexed) and the Client name, as well
as address and other key data
|
by: google |
last post by:
I have a database with four table. In one of the tables, I use about
five lookup fields to get populate their dropdown list. I have read
that lookup fields are really bad and may cause problems that are hard
to find. The main problem I am having right now is that I have a report
that is sorted by one of these lookup fields and it only displays the
record's ID number. When I add the source table to the query it makes
several records...
|
by: Greg Strong |
last post by:
Hello All,
Is it possible to change table field lookup properties in code?
I've been able to change other field properties in code, however so far
no luck with field lookup properties. What I've done for test purposes
is use a text input file for the table field lookup properties. I
thought that I'd start first by just changing the 'Display Control'
property. Thanks to Allen Browne for some ideals per...
| |
by: dancole42 |
last post by:
I'm self-taught in Access, and as such I'm missing large chunks of
knowledge, so I'm hoping someone here with some training can help me.
Right now I have an Invoice form with a Customer subform.
Right now it's set up so that someone can enter a customer ID, say,
12345, into the invoice form and customer 12345's name, address, etc.
shows up in the Customer subform.
How do I create a system where a user could start a new invoice, then
|
by: ApexData |
last post by:
How do I use a combo-box to do a lookup on my name table
“T-NAME”, and then place the values found in the lookup table (ie
LNAME, FNAME, MI) into to a row in my existing continuous forms table
"T-SICK" ?
I will have the combo-box lookup available in each row of my
continuous form bound to "T-SICK" to make this happen.
Thanks
|
by: Mark |
last post by:
I have a table with a field that uses a combobox to populate values. The
Lookup tab within table design mode is the following:
Display Control Combo Box
Row Source Type Table/Query
Row Source SELECT .LastName, .FirstName, .EmployeeNumber FROM ;
Bound Column 3
Column Count 3
Column Heads Yes
Column Widths 1";1";1"
|
by: David Wright |
last post by:
Hello Folks
I am using Microsoft Access 2000
I would be grateful if someone could help me with “Dlookup”. I tried various methods of writing Dlookup and various events to trigger it, none of which were successful. I have been able to display the required value in a ‘text box’ which is a little helpful but not ideal.
I have a table called tblLogSheet. The ‘Description’ field of this table uses a lookup table called...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |