Connecting Tech Pros Worldwide Forums | Help | Site Map

Filling a text box from a table

Member
 
Join Date: Jul 2007
Posts: 36
#1: Jul 9 '07
Hi again,

So basically what I'm trying to do is choose two pieces of information (General_Combo, and Pipelines) from combo boxes, then have a text box fill itself in based on the choices I've made with the combo boxes. The combo boxes match to a table where all the information is available to cross-reference and fill in the text box(Activity_ID, Region, Work_Order).

I tried to set it to the control source but instead of the Work_Order text in the table showing up in my text box, i'm getting "#Name?" Anyways, enough rambling. Here's my code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Pipelines_Click()
  2.  
  3. Forms.Layout.Worker.ControlSource = "SELECT Work Order.Work_Order " & _
  4. "FROM Work Order " & _
  5. "WHERE Forms.Layout.Pipelines = Work Order.Region" & _
  6. "AND Forms.Layout.General_Combo = Work Order.Activity_ID"
  7.  
  8. End Sub
If anyone could give me some suggestions on what's wrong with my code, or perhaps a better way to cross reference my data, I would really appreciate it.

Thanks,
Tiffany



NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#2: Jul 9 '07

re: Filling a text box from a table


It's not possible to reference names whch include embedded spaces without surrounding them in [].
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Pipelines_Click()
  2.  
  3. Forms.Layout.Worker = "SELECT [Work Order].Work_Order " & _
  4.                       "FROM [Work Order] " & _
  5.                       "WHERE Forms.Layout.Pipelines = [Work Order].Region " & _
  6.                       "AND Forms.Layout.General_Combo = [Work Order].Activity_ID"
  7.  
  8. End Sub
Also, Forms.Layout should probably be Forms("Layout") (except within the SQL string when it should be Forms('Layout'))
Is Worker really a TextBox? If it is it won't take a SQL string setting.
Member
 
Join Date: Jul 2007
Posts: 36
#3: Jul 9 '07

re: Filling a text box from a table


Ack! Ok you just went a little beyond my range of knowledge right there.

Layout is the name of my form. I'm not at all sure when to use ("Layout"), would you mind telling me what that format does?

Also, I think Worker is a text box...at least I used the toolbar button "text box" to make it. Is that why it's not properly reading my table? In which case, is there an object can I make that will accept the data?

Thanks,
Tiffany
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#4: Jul 9 '07

re: Filling a text box from a table


Rushing to finish for tonight Tiffany.
Look at Referring to Items on a Sub-Form as that will cover how to reference forms by name. Forms.Layout is not a way that works.
ListBoxes and ComboBoxes can take multiple rows, so could work with SQL SELECT strings.
Member
 
Join Date: Jul 2007
Posts: 36
#5: Jul 9 '07

re: Filling a text box from a table


Wow, I wasn't expecting a reply that quickly. Thank you
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#6: Jul 10 '07

re: Filling a text box from a table


Just the luck of the draw :)
Let me know how you get on with those.
Member
 
Join Date: Jul 2007
Posts: 36
#7: Jul 10 '07

re: Filling a text box from a table


Ok so I changed the text box to a list box which seems to be working better...I have numbers showing up now :) But I don't think it's checking my second conditional statement. I only know C++ so I'm basically writing this all using C++ and hoping it works with VB. For the most part it has but it won't accept my brackets for keeping my two conditional statements together. Any suggestions?
Expand|Select|Wrap|Line Numbers
  1. Private Sub Pipelines_Click()
  2.  
  3. Forms.Layout.WorkList.RowSource = "SELECT [Work Order].Work_Order " & _
  4. "FROM [Work Order]" & _
  5. "WHERE [Work Order].Region =" & Forms.Layout.Pipelines & _
  6. "AND Work Order.Activity_ID =" & Forms.Layout.General_Combo
  7.  
  8. End Sub
  9.  
I took out the brackets I originally had because I kept getting syntax errors.

Thanks,
Tiffany
Member
 
Join Date: Jul 2007
Posts: 36
#8: Jul 11 '07

re: Filling a text box from a table


Never mind, I figured it out. I missed a space. I hate code.

:)
Tiffany
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#9: Jul 11 '07

re: Filling a text box from a table


Nicely done (between lines 5 & 6).
As this is SQL code though, you shouldn't get too bogged down by the differences in syntax. We're here if you do of course ;)
Reply