473,513 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with form-combo boxes populating other fields.

5 New Member
I am trying to create a from that the user can select a street from a combo box (named street), then pick a second street from another combo box, containing only valid cross streets(named Cross). When the second combo box is completed I want a third control, a text box (named ID)to be filled in with a id for that intersection.

I have a table that contains the fields:
Fr--street name
To--cross street name
Node--The unique id for the intersection (this is only unique in that it describes a single point in space, not a unique record)

This table contains duplicates, i.e.:
Fr ______________To _____________ Node
8 ST NW ________2 AVE NW________101
2 AVE NW________8 ST SW __________101

It is possible that more than 2 records could have the same Node
I do not maintain the database that the table is created from and cannot change the design of the table in any way; I can however run any queries, or make tables to manipulate the data.

I have a form and am able to get the first combo box (Street) to work, and the second combo box (cross) to provide a list of only valid cross streets.

The problem is I cannot get the third control (ID) to populate with the value for node.
The closest I can get is
Expand|Select|Wrap|Line Numbers
  1. Private Sub cross_AfterUpdate()
  2. id = "select node from intlist where street.value=fr and cross.value=to"
  3. End Sub 
This only populates the ID field with a direct quote of the sql statement.

I have no idea where to go from here
Any help would be greatly appreciated.

I am working with access 2003 and windows xp professional.
Jul 19 '07 #1
5 1779
Scott Price
1,384 Recognized Expert Top Contributor
A couple of questions, what are the names of your combo boxes that choose the street and cross? One naming convention that makes it (MUCH) easier to write code is to prefix these with cbo...

It looks like in your SQL statement you are transposing the values that you are needing to use as criteria: i.e. fr needs to be equal to the value of your combo box street, not the other way around, also a little syntax correction is called for.

First of all you should to assign the value of your SQL statement to a variable first, instead of directly to the value of the combo box. Try changing this:
Expand|Select|Wrap|Line Numbers
  1.          Private Sub cross_AfterUpdate()
  2.          id = "select node from intlist where street.value=fr and cross.value=to"
  3.          End Sub
State your variables at the top of the code window immediately under Option Explicit...
Expand|Select|Wrap|Line Numbers
  1. Private Const strSQL1 = "SELECT node" & " FROM intlist WHERE fr = ' "
  2. Private Const strSQL2 = " ' AND to = "
  3. Private strSQL As String
Then in your AfterUpdate event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cross_AfterUpdate()
  2. strSQL = strSQL1 & Me!street.Value & strSQL2 & Me!cross.Value
  3. Me!id.Value = strSQL
  4. Me!id.Requery
  5. End Sub
You may not need the Requery method at the end, but try it first with, then if it throws up, comment that part out by prefixing with an '

Hope this helps!

Regards,
Scott
Jul 19 '07 #2
Scott Price
1,384 Recognized Expert Top Contributor
Something urgent has come up here, and I won't be able to get back to this thread until at least Monday. If you have more problems, post back here and hopefully one of the others will be able to take it from there.

I'll try to check in on Monday and see the progress. If you haven't had any more problems, and the fix has worked, please post here to let me know!

Thanks,
Scott
Jul 19 '07 #3
a Wellner
5 New Member
Ok

I took your suggestion and changed the names of the combo boxes to be prefixed by “cbo”. I am just learning VBA and SQL but I think I understand everything..

“It looks like in your SQL statement you are transposing the values that you are needing to use as criteria: i.e. fr needs to be equal to the value of your combo box street, not the other way around, also a little syntax correction is called for.”

So I need to list the field in my table first then the value that I want to compare it to.

I understand what you are saying about using variables, and changed the code to what you posted, now when I select values in the combo boxes I get something like this:
“select node from intlist where fr=1 AVE NE and to=1 ST NE”

I was able to get something like this before, however not with the street names listed, but I still need to get the actual value for the node.

Thank you for your help
Jul 19 '07 #4
Scott Price
1,384 Recognized Expert Top Contributor
Hello, I've just snatched a few minutes to work on this.

I set up in my test database a table called tblIntList with this structure:
Expand|Select|Wrap|Line Numbers
  1. IntID  AutoNumber PK
  2. iTo  Text
  3. iFrom  Text
  4. Node  Number
I then created a form based on this table. In the detail section of the form I left one text box visible called Node. The other text boxes with IntID, iTo and iFrom I made invisible (the last two weren't necessary for my purposes but may be for yours). I then created a select query called qryIntersection. In this query I chose to display the field IntID, then in the next field I gave it a custom name by entering the following: Intersection: [iTo] & ", " & [iFrom]

In the header section of this form I created a combo box called cboIntersection. I left this box unbound, but the Row Source field I set to qryIntersection... I made it have 2 columns, the column sizes are 0",2", the bound column is 1, and the Limit to List is set to Yes.

Then in the AfterUpdate event of this combobox, I wrote this code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboIntersection_AfterUpdate()
  2. IntTo = Me!cboIntersection.Value
  3. DoCmd.GoToRecord , , acGoTo, IntTo
  4. End Sub
This worked for me making the Node text box show up the value for the corresponding intersection.

I'm sorry that I won't be able to check back in on this Monday, I won't be back to my computer until probably Tuesday evening. Thought I'd throw this at you to see if it could help...

Regards,
Scott
Jul 22 '07 #5
Scott Price
1,384 Recognized Expert Top Contributor
BTW "To" is a reserved word in Access and Visual Basic, you should rename your field to something different so as to avoid confusing the poor computer :-)
Jul 22 '07 #6

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

Similar topics

3
3256
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
1
1823
by: GrelEns | last post by:
hello, i had a trouble with re that i didn't understand (this is a silly example to show, to parse html i use sgmllib) : having this string : >>> s = """<form name="test" method="post"...
5
2964
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
2
3282
by: chanchito_cojones | last post by:
hi there, I am needing some help with a database I am putting together. The database works off of a main Form, which then has buttons on it that will open up other forms. The problem I am having...
5
2596
by: TD | last post by:
Hey All, I am hooking up our custom html (.chm) help file to our Access xp application, and, despite reading several posts and manuals on this, I still have a gap in my understanding... OK, so...
1
1950
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
10
2507
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
9
7983
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a MDI Container Form, with one label control on the Background of this container form. When I now open a child form, this form is behind the label ... and this looks ugly ... :-))...
5
1816
by: pattersonc | last post by:
Hello! I'm new to this forum and also new to using ASP and SQL and Access. I am in need of some help. I'm trying to make a database to help my football team. I've pretty much got the whole thing...
1
3191
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
7259
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
7380
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,...
1
7098
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
5683
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,...
0
4745
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.