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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DagNabbit!!! why wont this string show in my textbox?

Status
Not open for further replies.

LuckyNate

Programmer
Nov 23, 2002
6
US
i have a question that needs answering, and i think this might be just the place......
I'm using a form w/ blank textboxes, (frmMainForm)...and a dataform(frmAutos) that shows data from an access database and also contains a "Select" button (cmdSelect)
clicking on any of the textboxes on frmMainForm opens frmAutos and displays the necessary data, upon clicking frmAutos.cmdSelect, the contents of each of frmAutos.textbox.text is copied to a public string variable, and then from there dumped into frmMain.textbox.text...the code looks kinda like this

private sub cmdSelect_Click()
strPublicString=txtfields(0).text
UpdateMainForm()
Unload Me
End Sub

Public sub UpdateMainForm()
frmMainForm.txtTargetTextBox.text=strPublicString
frmMainForm.refresh
End Sub()

If i step through the code, the value at frmMainForm.txtTargetTextBox.text does in fact equal the proper value after it is set, but for some odd reason it doesnt appear on screen at run-time....in other words the data is there, but you just can't see it...
Any help would be INCREDIBLE!!!!!
Also please let me know if there is an easier way to accomplish this task, because i actually feel as though this might be a bit circuitous programmatically.

 
Nate-

That does sound strange. I quickly created a series of forms and functions like what you described, and it worked fine (as long as you get rid of the parantheses after "End Sub" and after the call to "UpdateMainForm". It sounds like your problem is that strPublicString is going out of scope. Where do you declare it? I declared it as a public variable in frmAutos, and that worked fine for me.

If that's not the prob, did you make sure that txtTargetTextBox is both visible and enabled?

ed
[afro]
 
I declared the Public string variables in the main module (modMain) in the general declarations section.
the reason i declared these public strings there is because these values need to persist
within the variables for other functionality that will be added later on...im trying to keep the design as open to improvement as possible....
However, if this solution makes it work im going to fly w/ it LOL
 
Yeah, you're right, in general you should definitely keep the variable in a separate module if multiple forms share it.

But yeah, whatever works works... [wink]

ed
 
LOL i cant believe what the problem was.....
check it out, as i was stepping through i noticed that when i referenced frmMainForm in my code, it was calling form.load each time(innapproriately I might add)
so i started looking at my code more closely...
check out this line of code
set fMainForm=new frmMainForm
when i changed the frmMainForm in my code to fMainForm....IT WORKED!!!!
LOL i have been agonizing for weeks LOL
 
OK LuckyNate:

I think I have a very good solution for you. You CAN declare a variable as public in a module, but, in my opinion, it would be better to do this:

Create a property in the form by clicking in the menu (while you are in the code section of the form): Tools->Add Procedure

Select the optionm property.
Then you'll see two subroutines called with the name thet you've specified but preceeded with the LET or GET command.
Then, create a local variable.
the code should look like this:

'--this is a local variable
Dim PtextFromAnotherForm As String

'GET allows other objects to retreive the value of the property

Public Property Get textFromAnotherForm() As String
textFromAnotherForm = PtextFromAnotherForm
End Property

'GET allows other objects to change the value of the property

Public Property Let textFromAnotherForm(ByVal vNewValue As String)
PtextFromAnotherForm = vNewValue

'just pass to your textbox here the parameter that entered
End Property

This should work. This is a good object abstraction, if you ever programmed in C++ you'll be familiar whiut this type of properties.
Anything you need, please ask.
Gutes
 
Just so nobody gets confused, when Gutes said
Code:
'GET allows other objects to change the value of the property
,
he obviously meant LET.

Also, I don't know how familiar C++ programmers are with properties, but C# programmers definitely should be.

ed
[afro]
 
great gravy...that is a snazzy solution!
you guys have been Super helpful thanks a lot
im sure ill hit a bunch more stepping stones in this....my first real application for a real business LOL


p.s. I do program in c and in c++ and yeah i am familiar...LOL
thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top