473,800 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find cross table values

8 New Member
Hi, I've been looking through these pages and the net looking for an answer to my current problem - to no avail. I'm working on an access database, and triggering the on change event on a form I'm trying to figure out how to write this in VB.

I have two tables and a form.
Table one: value 1, more data
Table two: value 1, value 2, more data
Form: Field value 1, value 2

On my form I'm trying to enable, by choosing a value 1 from a combobox, based on table one, to retrieve value 2 and displaying it in a textbox on the same form.

I've tried several differnet options and have come to the conclusion that I must be looking at this the wrong way. It ought to be simple - but I just can't seem to nail it.

Please help me :)
May 9 '07 #1
3 1747
Dököll
2,364 Recognized Expert Top Contributor
Hi, I've been looking through these pages and the net looking for an answer to my current problem - to no avail. I'm working on an access database, and triggering the on change event on a form I'm trying to figure out how to write this in VB.

I have two tables and a form.
Table one: value 1, more data
Table two: value 1, value 2, more data
Form: Field value 1, value 2

On my form I'm trying to enable, by choosing a value 1 from a combobox, based on table one, to retrieve value 2 and displaying it in a textbox on the same form.

I've tried several differnet options and have come to the conclusion that I must be looking at this the wrong way. It ought to be simple - but I just can't seem to nail it.

Please help me :)
Hello, mnms!

Please do not take this the wrong way, I am slightly confused, as I have read this a couple of times:

(1) Is it my understanding you now need to build VB forms instead of MS Access forms

Or

(2) Will you keep the Access data table(s) and interact using VB forms

If you need to play aroung with combo boxes in VB, you may not need MS access, you can use a text file.

Please continue to ask questions, and it might be helpful to include what you have working thus far to see where you are.

Good luck and welcome!

Dököll
May 10 '07 #2
mnms
8 New Member
Hi Dököll,

Thanks for taking the time to answer me. I had hoped to avoid showing any code as I'm pretty sure it's faulty and not certain if that is the way to do it. And I'm sorry if I was too vague in my first description.
I'm working on an Access database and I'm using Access forms. I did wonder if I should have posted in the access forum but this seemed more appropriate. Anyway, back to the problem.
My database handles spent hours on projects (type designator). I haven't found out how to calculate the hours spent yet, so I know that part is faulty, I was focusing on how on earth to show any of the hours stored in the tblLog table on the current form, before I'd worry about the calculations. The Hours in tblLog is a time field calculated using the Timediff function. I've been using Access 2003 VBA as an example so if you recognize some naming from there there's a reason :).
Anyway the code in question looks like this so far:

Private Sub fTypeDesignator _AfterUpdate()
'calculate the total spent hours used for the chosen project
If IsNull(Me.fType Designator) Then
'do nothing
Exit Sub
Else

Dim rsContacts As ADODB.Recordset

'create new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
'With rsContacts
.CursorType = adOpenStatic
'only read-rights
.LockType = adLockReadOnly
'open the recordset based on tblContacts table using the existing connection
.Open "tblLog", CurrentProject. Connection

'This is the part I wanted help with:

.Open "SELECT [Hours] FROM TblLog WHERE [Type designator] = "" & Me.fTypeDesigna tor""", CurrentProject. Connection

'end of the part I wanted help with

End With
Do While Not rsContacts.EOF
spentHours = spentHours + rsContacts!Hour s
rsContacts.Move Next
Loop
'yes I know this isn't right:
spentHours = SUM(rsContacts)
'insert into fSpentHours on the form
Me.fSpentHours = spentHours
'close the recordset
rsContacts.Clos e
'set the recordset and connection to nothing
Set rsContacts = Nothing
End If

End Sub

I hope it was more clear this time.

Br,

MnMs
May 10 '07 #3
mnms
8 New Member
Heh - I found it out myself - I just needed to bang my head against the wall several times!
The solution was instead of a recordset to use DLookup()

But thanks again for taking the time to look at it - it was very much appreciated! :D
May 10 '07 #4

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

Similar topics

9
1922
by: Simon Harris | last post by:
Hi All, Ok - I'll confess from the start, this is more about application logic that ASP, being an ASP programmer, I guessed you people might be able to help! :) I have built a room bookings system, based on ASP/SQL Server. Bookings are stored in a table, which holds start date+time and End date+time, amougst other info. Bookings can run from 8:30 - midnight, and are always made in 30 min blocks (e.g. 14:30 - 15:30 etc)
1
7512
by: Tim Pascoe | last post by:
I am using the Dynamic Cross-Tab code supplied in an article from SQL Server Magazine (http://www.winnetmag.com/SQLServer/Article/ArticleID/15608/15608.html). I modified the script to generate a temp table inside the stored procedure, and then use this temp table as the source for the cross-tab. However, the problem seems to be that the dynamic SQL string generated by the script is longer than what can be stored in the @SQL variable. The...
18
3768
by: Shannon Jacobs | last post by:
Trying to solve this with a regex approach rather than the programmatic approach of counting up and down the levels. I have a fairly complicated HTML page that I want to simplify. I've been able to mung most of it using several regular expressions, but I've become stuck at this point. I can't figure out how to grab only the <tr> tags that are associated with tables that are two levels deep. I feel like I got close, but it seems that...
3
7884
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works something like this: For a (very) simple table containing three rows like this: row 1: A
4
6608
by: SQLJunkie | last post by:
Here is an issue that has me stumped for the past few days. I have a table called MerchTran. Among various columns, the relevant columns for this issue are: FileDate datetime , SourceTable varchar(25) SQL statement: SELECT DISTINCT FileDate
16
2083
by: Justin Hoffman | last post by:
This is a question concerning query optimisation. Sorry if it's a bit long, but thanks to anyone who has the patience to help - This is my first post here... If I have two tables: 'tblContact' and 'tblCategory' where categories are like: Code Name 010101 Short 010102 Fat
4
5586
by: David Peach | last post by:
Hello, hope somebody here can help me... I have a query that lists defects recorded in a user defined date range. That query is then used as the source for a Cross Tab query that cross-tabs count of defect type by calendar month. Defect types are stored in one table, defect transactions in another along with date etc. When I cross-tab the results, defect types that have no defects recorded against them appear as a blank (null) value. That...
2
3696
by: Questman | last post by:
Good afternoon, Does anyone have any code that implements, or approaches implementing, a cross-browser DHTML/JS solution to provide an Excel-like Grid on a web page - I'm trying to convert an old Java client/server data maintenance program to the web - the main display is in a grid format, which allows the user to select multiple rows and edit them in a new grid, which processes each grid line individually and validates and saves the...
0
1287
by: nathancockram | last post by:
In the Cross-Tab Expert I have the following values: Columns --Table.ValY Rows --Table.ValX Summarized Fields --Table.Val1, Table.Val2, Table.Val3, Table.Val4, Table.Val5 CASE 1 CASE 2 Table.Val1 :: 0 3 Table.Val2 :: 0 0
0
9551
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,...
0
10504
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, 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...
1
10251
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
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...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
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...

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.