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

Error passing string

P: 42
Hi all

Trying to pass the value from a textbox to another form and i get an error .
The error is this :

Microsoft Office Access can't find the field "|" referred to in your expression.

What i have is a form called " names_form", with a textbox called "txtname" and another form called "searched_form" , with a label called "lbl_searchedtext"
When i type some text into "txtname" and i click a button , i want to display the text in the label " lbl_searchedtext" on the "searched_form".

The code i have now is this, and is placed on the "searched_form" load event.

Expand|Select|Wrap|Line Numbers
  1.  Dim text As String
  2. text = [names_form]![txtname].text
  3. lbl_searchedtext.Caption = text
  4. lbl_searchedtext.Visible = True 
I found the code somewhere online and the guy who posted said is working ,but for me is NOT,
Any help , please.
May 21 '09 #1
Share this Question
Share on Google+
13 Replies


P: 42
I have to say sorry again to NeoPa , tried to use the [code] tag ,but i can see that i got it worg again .
Do u mind sending me a message explaing how to use those tags , please ,cose i don't want to be banned or something.
Thanks , and sorry again!
May 21 '09 #2

missinglinq
Expert 2.5K+
P: 3,532
When writing your post simply do it like this

[ code ]
'Your code goes here
[ /code ]

When you actually do this, you have to eliminate the spaces between the brackets and code and /code for it to work.

Linq ;0)>
May 21 '09 #3

Denburt
Expert 100+
P: 1,356
Try this:
Expand|Select|Wrap|Line Numbers
  1.  Dim text As String
  2. text = Forms![names_form]![txtname].text
  3. Me!lbl_searchedtext.Caption = text
  4. Me!lbl_searchedtext.Visible = True
May 21 '09 #4

P: 42
Not working .
The same error again .
May 21 '09 #5

P: 42
no . sorry now is this error:

you can't refference a property or method for a control unless the control has the focus.

and is pointing on this line
Expand|Select|Wrap|Line Numbers
  1. text = Forms![names_form]![txtname].text
May 21 '09 #6

Denburt
Expert 100+
P: 1,356
ok I am nearing the end of a long day here I just realized also that you used text as a variable and although you did declare it in a Dim statement it is likely a reserved word. on strings I usually in str to help me try to avoid things such as that. This should work though:
Expand|Select|Wrap|Line Numbers
  1.  Dim strText As String
  2. strText = Forms![names_form]![txtname]
  3. Me!lbl_searchedtext.Caption = strText
  4. Me!lbl_searchedtext.Visible = True
  5.  
May 21 '09 #7

P: 42
ok I am nearing the end of a long day here I just realized also that you used text as a variable and although you did declare it in a Dim statement it is likely a reserved word. on strings I usually in str to help me try to avoid things such as that. This should work though:
Expand|Select|Wrap|Line Numbers
  1.  Dim strText As String 
  2. strText = Forms![names_form]![txtname] 
  3. Me!lbl_searchedtext.Caption = strText 
  4. Me!lbl_searchedtext.Visible = True 

Still not working.
??
May 21 '09 #8

missinglinq
Expert 2.5K+
P: 3,532
This code never worked for anyone, not in the fashion you've described, not in Access!

text = [names_form]![txtname].text

will only work if [txtname] has focus, and it obviously doesn't when it's not on the current (Searched_Form) form! And Text should not be used as a variable name, as it's a Reserved Word in Access.

In your first form, behind your button to open the the form Searched_Form, use the OpenArgs to send the TextName value to the label on the second form:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourCommandButtonName_Click()
  2.   DoCmd.OpenForm "Searched_Form", , , , , , Me.TextName
  3. End Sub
Then in the Searched_Form load event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   If Not IsNull(Me.OpenArgs) Then 
  3.    lbl_searchedtext.Caption = Me.OpenArgs
  4.    lbl_searchedtext.Visible = True 
  5.  End If
  6. End Sub
If you need to, you can include other arguments in your Open Form command as well.

Linq ;0)>
May 21 '09 #9

P: 42
Right , it makes sens now ,but the only problem is that behind the button i run a Macro which opens the Second Form.
How do i put the cod in there??
May 21 '09 #10

P: 42
In design View of the Macro , i have a set of actions .

Can i use one of those actions to put the code in there and if yes which one do i have to use?
May 22 '09 #11

P: 42
My Macro is doing this at the moment:

OpenQuery - query to search
OpenForm - searched form [searched_form] (where i want to pass the string)
Close - query to search
Close - names form [names_form]
May 22 '09 #12

NeoPa
Expert Mod 15k+
P: 31,709
@onyris
No worries if you've made the attempt Onyris :)

Here are a couple of generally helpful pointers for posting on Bytes. I noticed your code wasn't compiled as the .Text part of line #2 is displayed as .text.

CODE TAGS

Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).

POSTING UNCOMPILED CODE
It is always a good idea to ensure that variable name checking is enabled, AND your code compiles (at least compilation has been attempted), before submitting a question.

This avoids asking questions which are much more easily resolved on your own PC than on a forum.

To ensure variable name checking is enabled for all new modules, go to - Tools / Options / Editor (from the VBA Editor window) and set Require Variable Declaration to True (checked). For existing modules, ensure that the Option lines at the very top include :
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
To compile your project, select (again from the VBA Editor window) Debug / Compile Project Name.

We ARE generally happy to help with compilation problems too (If you find an error reported and you can't resolve it, let us know), but we do expect members to have tried compiling before submitting a question. That way we have a better idea of the sort of problem we're looking at.
May 23 '09 #13

NeoPa
Expert Mod 15k+
P: 31,709
@onyris
Generally Macros are not very widely used. Full control is at least difficult when constrained to usage of macros.

Instead you can use VBA code. If you are using VBA code then it is sensible to replace your macro with VBA code which can then include this code that you're currently working through.

Does this make sense?
May 23 '09 #14

Post your reply

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