472,142 Members | 1,263 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

Getting a value from an input on another form

markmcgookin
648 Expert 512MB
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
14 33010
willakawill
1,646 1GB
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
648 Expert 512MB
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
14,534 Expert Mod 8TB
Is frmLogin open when you try to run this code?
Dec 3 '06 #4
markmcgookin
648 Expert 512MB
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
32,498 Expert Mod 16PB
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
648 Expert 512MB
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
32,498 Expert Mod 16PB
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
648 Expert 512MB
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
willakawill
1,646 1GB
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
1,754 Expert 1GB
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
648 Expert 512MB
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
32,498 Expert Mod 16PB
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
648 Expert 512MB
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
32,498 Expert Mod 16PB
All cool. :)
Dec 6 '06 #15

Post your reply

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

Similar topics

4 posts views Thread by beveled edges | last post: by
11 posts views Thread by Ray Muforosky | last post: by
8 posts views Thread by =?Utf-8?B?QW1yaXQgS29obGk=?= | last post: by
reply views Thread by buntyindia | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.