Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Daft Textbox question...?

Status
Not open for further replies.

lee007uk

Programmer
Aug 14, 2003
6
GB
hello programmer types...
how do u pull the information from a textbox??

i thought it would be really easy, i managed to do all sorts of things but not pull information from a textbox and use it.

Sorry for asking such a easy question but the help file don't tell me (well i can find it...) and nothing on any forums...

Cheers Guy and Gals
 
Try returning the data from your text box by storing it in a variable...

myvariable = textbox1.text

Let me know how you get on..........

Cheers

John
 
i try that and it comes up with :

Run-time error '424'

Object required

i thought it would be easy, but i'm sure i'm missing something really obivous....

i'm using excel VBA, does that make a difference?
 
Code:
Dim MyVariable as String
MyVariable = TextBox1.Value

The variable needs to be declared before you can give it a value.

What program are you using anyway, and where is the textbox value supposed to be going?



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
The variable doesn't need to be declared b4 you assign a value to it because vba will automatically assign the variable as a variant type. ( unless you have an option explicit statement )

It is obviously more efficient to declare the variable b4 using it.
 
i've done as u said and still get the same error...
it's just normal Excel 2000....

The textbox is used to specify the directory where a file is being saved, the name of the file is automatically created

all the automatic creating of file name and organising information works fine, it's just this last bit!

grrr!

been messing about for a couple of days and getting bored of it now!!

The help files are rubbish, and noone seems to do this, only help i find is how to put information from VB into a textbox...not the other way around....is there a better way of doing this?

little note my boss will want to do as little work as possible when it comes to using this thing (program...)i'm writing...
 
Where did you declare the variable?
does it need to be public?
where is it referenced from?
 
Could you show us a copy of your code so that we can get a better idea as to what it is you want to do?



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
right here's me code....
it's a bit messy as it's one of the first ones i've done, i declare at the top CoilQDir and SaveDir, then just below i try and move the textbox information in the variables....

hope this makes sense to someone!

Cheers guys

Sub Load_Spec()
'
' Load_Spec Macro
' Macro created by Lee Howard
'
'
Dim MyTime ' Return current system time
Dim SaveName As String ' Name of File to be saved
Dim JobNumber As String ' Current Job Number
Dim CoilQDir As String
Dim SaveDir As String

MyTime = Time
CoilQDir = Me.TextBox2.Value
SaveDir = Me.TextBox1.Value

' Open Spec File created by CoilQ

Workbooks.OpenText FileName:=CoilQDir & "SPEC", Origin:=xlWindows, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1)

JobNumber = Worksheets(1).Range("A1") ' Specify job number
SaveName = SaveDir & JobNumber & ".xls " ' Specify file name to save

' Check if the current CoilQ job exists

If Dir(SaveDir & JobNumber & ".xls ") = "" Then

' File does not exits so create a new file

Workbooks.Open FileName:=CoilQDir & "SPEC" ' Activate spec file
Columns("A:A").Select ' Select Column A
Selection.Insert Shift:=xlToRight ' Insert a new column and shift everything right

' After inserting a new column enter all of the title for the CoilQ data

Range("A1").Select
ActiveCell.FormulaR1C1 = "Code Name"
Range("A2").Select
ActiveCell.FormulaR1C1 = "Reference Number"
Range("A3").Select
ActiveCell.FormulaR1C1 = "Date"
Range("A4").Select
ActiveCell.FormulaR1C1 = "Coil Length"
Range("A5").Select
ActiveCell.FormulaR1C1 = "Mandril Size"
Range("A6").Select
ActiveCell.FormulaR1C1 = "Copper Width"
Range("A7").Select
ActiveCell.FormulaR1C1 = "Copper Thickness"
Range("A8").Select
ActiveCell.FormulaR1C1 = "Waterway Width"
Range("A9").Select
ActiveCell.FormulaR1C1 = "Waterway Depth"
Range("A10").Select
ActiveCell.FormulaR1C1 = "Insulation/face"
Range("A11").Select
ActiveCell.FormulaR1C1 = "Space Thickness"
Range("A12").Select
ActiveCell.FormulaR1C1 = "Number of Layers"
Range("A13").Select
ActiveCell.FormulaR1C1 = "Section Reference"
Range("A14").Select
ActiveCell.FormulaR1C1 = "Diameter"
Range("A15").Select
ActiveCell.FormulaR1C1 = "Length"
Range("A16").Select
ActiveCell.FormulaR1C1 = "Resistivity"
Range("A17").Select
ActiveCell.FormulaR1C1 = "Permeability"
Range("A18").Select
ActiveCell.FormulaR1C1 = "Start Temp."
Range("A19").Select
ActiveCell.FormulaR1C1 = "Final Temp."
Range("A20").Select
ActiveCell.FormulaR1C1 = "Heat Content"
Range("A21").Select
ActiveCell.FormulaR1C1 = "Density"
Range("A22").Select
ActiveCell.FormulaR1C1 = "Material"
Range("A23").Select
ActiveCell.FormulaR1C1 = "Billets/Hour"
Range("A24").Select
ActiveCell.FormulaR1C1 = "Kilogram/Hour"
Range("A25").Select
ActiveCell.FormulaR1C1 = "Handling Tiem"
Range("A26").Select
ActiveCell.FormulaR1C1 = "Soak Time"
Range("A27").Select
ActiveCell.FormulaR1C1 = "Billets in coil"
Range("A28").Select
ActiveCell.FormulaR1C1 = "Thermal Eff'y"
Range("A29").Select
ActiveCell.FormulaR1C1 = "Frequence"
Range("A30").Select
ActiveCell.FormulaR1C1 = "Phase Voltage"
Range("A31").Select
ActiveCell.FormulaR1C1 = "Number of Phases"
Range("A32").Select
ActiveCell.FormulaR1C1 = "Power Factor"
Range("A33").Select
ActiveCell.FormulaR1C1 = "Coil Efficiency"
Range("A34").Select
ActiveCell.FormulaR1C1 = "Coil Power Factor"
Range("A35").Select
ActiveCell.FormulaR1C1 = "Line Consumption"
Range("A36").Select
ActiveCell.FormulaR1C1 = "Coil Current"
Range("A37").Select
ActiveCell.FormulaR1C1 = "Phase Voltage"
Range("A38").Select
ActiveCell.FormulaR1C1 = "Phase Power"
Range("A39").Select
ActiveCell.FormulaR1C1 = "Phase KVA"
Range("A40").Select
ActiveCell.FormulaR1C1 = "Capacitive KVAR"
Range("A41").Select
ActiveCell.FormulaR1C1 = "Turns/Phase"
Range("A42").Select
ActiveCell.FormulaR1C1 = "Discs/Phase"
Range("A43").Select
ActiveCell.FormulaR1C1 = "Disc Pair Voltage"
Range("A44").Select
ActiveCell.FormulaR1C1 = "Disc Pair Loss"
Range("A45").Select
ActiveCell.FormulaR1C1 = "Disc Pair Flow"
Range("A46").Select
ActiveCell.FormulaR1C1 = "Trans KVA/Phase"
Range("A47").Select
ActiveCell.FormulaR1C1 = "D/P Copper Length"

Rows("4:4").Select ' Select Column 4
Selection.Insert Shift:=xlDown ' Insert a new row and shift everthing down
Range("A4").Select ' select A4
ActiveCell.FormulaR1C1 = "Time" ' Enter the text time
Range("B4").Select ' Select A5
ActiveCell.FormulaR1C1 = Time ' Enter the variant Time
Range("B5").Select

Cells.Select ' Select All
Cells.EntireColumn.AutoFit ' Resize all column and rows to fit new information

' Save the new job

ActiveCell.FormulaR1C1 = JobNumber
ActiveWorkbook.SaveAs FileName:= _
SaveName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

' File does exist so open it and add new data

Else
Workbooks.Open FileName:=SaveDir & JobNumber & ".xls "

Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Workbooks.OpenText FileName:="G:\COILQ\SPEC", Origin:=xlWindows, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1)
Columns("A:A").Select
Selection.Copy
Windows(JobNumber & ".xls").Activate
Range("B1").Select
ActiveSheet.Paste
Range("B4").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Range("B4").Select
ActiveCell.FormulaR1C1 = Time

Cells.Select ' Select All
Cells.EntireColumn.AutoFit ' Resize all column and rows to fit new information


ActiveCell.FormulaR1C1 = JobNumber
ActiveWorkbook.Save

Workbooks("SPEC").Close SaveChanges:=False

End If

End Sub

 
Which line are you receiveing the error message on?

Do you have a closing backslash "\" at the end of the text in your textboxes? I have to ask, because they are not hardcoded.





Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
CoilQDir = Me.TextBox2.Value

is where the program stops

yep got a closing \ on the end of the directory
 
i got the solution!!!

you have to specify the sheet and the name of the textbox e.g

MyVariable = Sheets(1).TextBox1.Text

cheers for ur help guys...

any one want to run there eyes over the code and tell me anything else that i've done wrong, or could be done better??
 
With the Me. before the TextBoxes, I am sure that we were all assuming that they were on a UserForm.

I'm glad you got it figured out though.



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top