By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,400 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,400 IT Pros & Developers. It's quick & easy.

Getting a value from an input on another form

markmcgookin
Expert 100+
P: 648
Hi guys,

I am trying to get a value from a textbox on a form to use in another, seperate form, i have tried
Expand|Select|Wrap|Line Numbers
  1. Dim username As String
  2.  
  3. Forms!frmLogin!txtMembername = Me.Text1
  4. username = Text1
  5. MsgBox "" & username
  6.  
(I made a textbox called text1 and made it invisible because I kept haveing errors assigning the value to a variable eg. UserName, but it didn't work, but thats why it is in there!)

I have looked at the other threads on this subject, but I can't understand why I keep getting errors (that code give me an invalid use of null error even when the other form is open and txtMemberName has text in it. Although, every time i run this it wipes the field in the other form too...which is annoying)

Cheers for any responces!

Mark
Dec 3 '06 #1
Share this Question
Share on Google+
14 Replies


100+
P: 1,646
Hi guys,

I am trying to get a value from a textbox on a form to use in another, seperate form, i have tried
Expand|Select|Wrap|Line Numbers
  1. Dim username As String
  2.  
  3. Forms!frmLogin!txtMembername = Me.Text1
  4. username = Text1
  5. MsgBox "" & username
  6.  
(I made a textbox called text1 and made it invisible because I kept haveing errors assigning the value to a variable eg. UserName, but it didn't work, but thats why it is in there!)

I have looked at the other threads on this subject, but I can't understand why I keep getting errors (that code give me an invalid use of null error even when the other form is open and txtMemberName has text in it. Although, every time i run this it wipes the field in the other form too...which is annoying)

Cheers for any responces!

Mark
Hi Mark,
I am going to assume that 'the other form' is Forms!frmLogin and your code above is the current form:

Expand|Select|Wrap|Line Numbers
  1. Me.Text1.Text = Forms!frmLogin!txtMembername.Text
  2. username = Me.Text1.Text
  3. MsgBox username
Of course I don't know if your intention with the message box is simply debugging, otherwise you would just write:

Expand|Select|Wrap|Line Numbers
  1. MsgBox Forms!frmLogin!txtMembername.Text
Dec 3 '06 #2

markmcgookin
Expert 100+
P: 648
Hi Mark,
I am going to assume that 'the other form' is Forms!frmLogin and your code above is the current form:

Expand|Select|Wrap|Line Numbers
  1. Me.Text1.Text = Forms!frmLogin!txtMembername.Text
  2. username = Me.Text1.Text
  3. MsgBox username
Of course I don't know if your intention with the message box is simply debugging, otherwise you would just write:

Expand|Select|Wrap|Line Numbers
  1. MsgBox Forms!frmLogin!txtMembername.Text
Hi, Sorry yeah it was just there for debugging!

I get this error now, I can't figure out why though,

"Run time error '2185'

You can't reference a property or method for a control unless the controll has a focus"

If you figure it out could you explain it a bit me?

Cheers

Mark
Dec 3 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Is frmLogin open when you try to run this code?
Dec 3 '06 #4

markmcgookin
Expert 100+
P: 648
Is frmLogin open when you try to run this code?
Yeah I have it open and have a value in the txtMemberName field too. Weird, you can get the DB from http://www.cmdclan.co.uk/Temp/jr_system.mdb if you want an actual look at it, the test form I am using is just the form1 form, and the one I am reading from is the frmLogin

Cheers

Mark
Dec 3 '06 #5

NeoPa
Expert Mod 15k+
P: 31,661
Mark,

I tried the version below and it worked fine.
I lost the .Text bits and added in the Nz() as an empty name would have caused the code to crash.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2. Dim username As String
  3.  
  4. Me.Text1 = Forms!frmLogin!txtMembername
  5. username = Nz(Me.Text1, "")
  6. MsgBox username
  7.  
  8. End Sub
Dec 3 '06 #6

markmcgookin
Expert 100+
P: 648
Mark,

I tried the version below and it worked fine.
I lost the .Text bits and added in the Nz() as an empty name would have caused the code to crash.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2. Dim username As String
  3.  
  4. Me.Text1 = Forms!frmLogin!txtMembername
  5. username = Nz(Me.Text1, "")
  6. MsgBox username
  7.  
  8. End Sub
Hi

I still couldn't get that to work, so the button on form1 now does

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2. Dim username As String
  3.  
  4. username = Nz(Forms!frmLogin!txtMembername, "")
  5. MsgBox username
  6. End Sub
  7.  
And that seems to work fine! haha,

I changed the function of Login to point to that form1 form, but that is just for the purposes of debugging,

thanks for all your help!

Mark
Dec 4 '06 #7

NeoPa
Expert Mod 15k+
P: 31,661
I've no idea why you couldn't get it to work but I suppose that now it's working that's no longer a problem ;)
Dec 4 '06 #8

markmcgookin
Expert 100+
P: 648
I've no idea why you couldn't get it to work but I suppose that now it's working that's no longer a problem ;)
Yeah it's weird the way things just don't work sometimes, especially when one person can get them to work... Ghost in the Machine I guess
Dec 4 '06 #9

100+
P: 1,646
Yeah it's weird the way things just don't work sometimes, especially when one person can get them to work... Ghost in the Machine I guess
It might be weird and it is the time when there is most learning taking place if you stick with it. There is no ghost in the machine, just things to learn :)
Dec 5 '06 #10

sashi
Expert 100+
P: 1,754
Hi there,

Lets see if this link helps get rid of the GHOST in your machine, hope it helps. Good luck & Take care. :)

Variable Scope
Dec 5 '06 #11

markmcgookin
Expert 100+
P: 648
Hi there,

Lets see if this link helps get rid of the GHOST in your machine, hope it helps. Good luck & Take care. :)

Variable Scope
Hehe, i like the sound that code made as it wooshed over my head. I looked away as soon as I saw the extention .dll :o)

My system is a throw away prototype that just has to demonstrate an overall functionally, but not BE that functional. If you catch my drift, I'm trying to learn VB8 with SQL Server CE or a mobile app im writing, and it is complicated enough without trying to learn all this razamatazz hehe.
Dec 5 '06 #12

NeoPa
Expert Mod 15k+
P: 31,661
Mark,

I'm sure you didn't mean to sound critical, but please bear in mind that these members are trying to help you and have no way of knowing how appropriate a suggestion is for you personally.
Dec 5 '06 #13

markmcgookin
Expert 100+
P: 648
Mark,

I'm sure you didn't mean to sound critical, but please bear in mind that these members are trying to help you and have no way of knowing how appropriate a suggestion is for you personally.
Yeah I wasn't being critical at all! Sorry guys, I really appreciate all your help! Didn't mean to sound arsy. You have saved my bacon in these forums with your advice already, I have the upmost respect for all of you!

Cheers

Mark
Dec 6 '06 #14

NeoPa
Expert Mod 15k+
P: 31,661
All cool. :)
Dec 6 '06 #15

Post your reply

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