468,549 Members | 2,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,549 developers. It's quick & easy.

Filling a text box from a table

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
Jul 9 '07 #1
8 2240
NeoPa
32,101 Expert Mod 16PB
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.
Jul 9 '07 #2
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
Jul 9 '07 #3
NeoPa
32,101 Expert Mod 16PB
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.
Jul 9 '07 #4
Wow, I wasn't expecting a reply that quickly. Thank you
Jul 9 '07 #5
NeoPa
32,101 Expert Mod 16PB
Just the luck of the draw :)
Let me know how you get on with those.
Jul 10 '07 #6
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
Jul 10 '07 #7
Never mind, I figured it out. I missed a space. I hate code.

:)
Tiffany
Jul 11 '07 #8
NeoPa
32,101 Expert Mod 16PB
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 ;)
Jul 11 '07 #9

Post your reply

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

Similar topics

1 post views Thread by dhunter | last post: by
3 posts views Thread by crjunk | last post: by
11 posts views Thread by Sid Price | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.