473,414 Members | 1,944 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,414 software developers and data experts.

How to find cross table values

8
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 1730
Dököll
2,364 Expert 2GB
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
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.fTypeDesignator) 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.fTypeDesignator""", CurrentProject.Connection

'end of the part I wanted help with

End With
Do While Not rsContacts.EOF
spentHours = spentHours + rsContacts!Hours
rsContacts.MoveNext
Loop
'yes I know this isn't right:
spentHours = SUM(rsContacts)
'insert into fSpentHours on the form
Me.fSpentHours = spentHours
'close the recordset
rsContacts.Close
'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
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
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...
1
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...
18
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...
3
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...
4
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...
16
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:...
4
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...
2
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.