473,471 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

My code doesn't wants to set the control default value

759 Contributor
Hello !

I try to open a form from the NotInList event (check box) and to pass the NewData as OpenArgs.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmContoare_tipuri", , , , , acDialog, NewData
Here is the Load event in the form I wish to open (frmContoare_tipuri)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     If Not IsNull(Me.OpenArgs) Then
  3.         Tip.DefaultValue = Me.OpenArgs
  4.     End If
  5. End Sub
But I've obtained the #Name? (see attachment)in the Tip field

Also I've tried to use the Open event but with the same result.

In order to debug, I use this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current() 'Debug
  2.     MsgBox Tip.DefaultValue
  3. End Sub
And the message is what I expected to be: the right value (also you can see this in attached word file)

Any idea ?

Thank you !
Attached Files
File Type: doc Doc1.doc (157.5 KB, 188 views)
Aug 7 '13 #1
11 1609
jimatqsi
1,271 Recognized Expert Top Contributor
Mihail, that's a curious one. Have you verified that your code in Form_Load is the culprit? If you comment out
Expand|Select|Wrap|Line Numbers
  1. Tip.DefaultValue = Me.OpenArgs
does the error go away?

Jim
Aug 7 '13 #2
Mihail
759 Contributor
I open this form from two different places.
From other place I open this form without OpenArgs (it is why I have the IF statement in Form_Load) and all is OK.

So I'm very sure that this code bring me in trouble.
Just, like you, I don't understand why.

Maybe you should know that I have also this code in frmContoare_tipuri.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Call FormMoveResize(Me)
  3.     DoCmd.GoToRecord , , acNewRec
  4. End Sub
But, I repeat: All is OK if I don't open with OpenArgs.

Thank you for reply !
Aug 7 '13 #3
jimatqsi
1,271 Recognized Expert Top Contributor
There's more happening than we can see from these posts. I doubt changing the default value property is causing the problem.

The thing is, that "#Name" usually appears in a control when the control source doesn't appear in the recordsource of the form. But in a continuous form, one would expect it on every row if it happens at all.

I would still comment out that line and verify the problem stops happening when you don't execute
Expand|Select|Wrap|Line Numbers
  1. Tip.DefaultValue = Me.OpenArgs
. I have an idea that the problem will continue.

The form's order of events is Open ->Load ->Resize ->Activate ->Current

I believe you should reconsider what you have happening in each of those events. Right now the default property is being set AFTER you have moved to the new record row.

Jim
Aug 7 '13 #4
Mihail
759 Contributor
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Call FormMoveResize(Me)
  3.     DoCmd.GoToRecord , , acNewRec
  4.     If Not IsNull(Me.OpenArgs) Then
  5.         Tip.DefaultValue = Me.OpenArgs
  6.     End If
  7. End Sub
I would still comment out that line and verify the problem stops happening when you don't execute
Expand|Select|Wrap|Line Numbers

Tip.DefaultValue = Me.OpenArgs

. I have an idea that the problem will continue.
Unfortunately :) the problem disappear when I do this. All is OK if I comment this line.

I believe you should reconsider what you have happening in each of those events. Right now the default property is being set AFTER you have moved to the new record row.
I've tried this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Call FormMoveResize(Me)
  3.     DoCmd.GoToRecord , , acNewRec
  4.     If Not IsNull(Me.OpenArgs) Then
  5.         Tip.DefaultValue = Me.OpenArgs
  6.     End If
  7. End Sub
but with exactly the same result.
Aug 7 '13 #5
jimatqsi
1,271 Recognized Expert Top Contributor
You must put the default value property setting prior to your
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec
The moment you go to a new record the DefaultValue property is needed, but you haven't plugged it in yet. Line 3 should appear after line 6.

That doesn't explain why you're getting what you're getting, but it will prevent you from getting the tip default you want.

You might try putting this in the OnCurrent event
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.OpenArgs) Then ' tip default passed in OpenArgs?
  2.     If Len(Nz(Me.tip)) = 0 Then ' Is this a new entry?
  3.         Me.tip = OpenArgs
  4.     End If
  5. End If
  6.  
That could be another way to achieve the same result, but without ever knowing why the first idea did not work.

Jim
Aug 7 '13 #6
Mihail
759 Contributor
As you can see I have tried this. No change.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     If Not IsNull(Me.OpenArgs) Then
  3.         Me.Tip.DefaultValue = Me.OpenArgs
  4.     End If
  5.     DoCmd.GoToRecord , , acNewRec
  6. End Sub
  7.  
  8. Private Sub Form_Open(Cancel As Integer)
  9.     Call FormMoveResize(Me)
  10. '    If Not IsNull(Me.OpenArgs) Then
  11. '        Me.Tip.DefaultValue = Me.OpenArgs
  12. '    End If
  13. '    DoCmd.GoToRecord , , acNewRec
  14. End Sub
I'll try to avoid as much as possible to set the value for the field in code.
That because the user can change his mind and the fields are, both of them, required.
Aug 7 '13 #7
Mihail
759 Contributor
Founded the answer (with the help from other forum):
Expand|Select|Wrap|Line Numbers
  1. Me.Tip.DefaultValue = "'" & Me.OpenArgs & "'"
Works also with double quotes:
Expand|Select|Wrap|Line Numbers
  1. Me.Tip.DefaultValue = """" & Me.OpenArgs & """"
Thank you for your time and patience !

Cheers !
Aug 8 '13 #8
jimatqsi
1,271 Recognized Expert Top Contributor
Thank you for posting the solution. That was a tricky one.
Aug 8 '13 #9
Mihail
759 Contributor
This forums should be (in my opinion) a school for every one.
Bytes policy don't allow me to post a link to other forums. OK. I am a guest here and I must respect their rules. No problem. But I like to inform you (all) that I post my question ONLY here. In the Bytes. The reason was that I have not can access the "other" forum, at that time. Then, in that "other forum" I post a link and an ask. And they have helped me with no problem.
And no one attempt to remove my post as I think that will happen with this one (unfortunately). And I don't refer to you, jimatqsi.

One more info related to the thread's subject:
The same guy that give me the solution have said that the same #name? error is raised if the size of the field is too small. I don't test yet.

All the best to all !
Aug 8 '13 #10
jimatqsi
1,271 Recognized Expert Top Contributor
Mihail, I have always found Bytes to be a very, very good place to get information. I have learned so much on this forum, and I'm very grateful for that. And sometimes I use other forums when it is necessary, but Bytes is my favorite.

Within the last year I think they have eliminated the ban on links to other sites. I know I have put links in several recent posts.

Thanks for sharing your thoughts. I look forward to seeing more posts from you, maybe solving my problems. :)

Jim
Aug 9 '13 #11
zmbd
5,501 Recognized Expert Moderator Expert
It's my understanding that links to other forums that compete directly with Bytes are still frowned on; however they may not be automatically removed - either directly from the post, or by removing the post. I know that I would tend to simply redact the direct url link and leave the post and the reference to the site.

The issue with links is that they tend to become obsolete.
It is usually preferred to also include the relevant information; thus, the link becomes like a citation in a book.
Aug 12 '13 #12

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

Similar topics

2
by: akl | last post by:
How can I create such a default value that it depends on the value in other field (drop down)? So that the default value would be updated every time I change the value of drop-down field.
2
by: Terry Bickle | last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4 macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB. I'm sure there is a simple Access 101...
3
by: Todd D. Levy | last post by:
I have a number of Drop Down Combo Boxes where users select a country; 99% of the time the selection will be "United States". I want to use VBA code in the New Record Event to populate this field...
6
by: MLH | last post by:
I have a form named frmVehicleEntryForm. It has a 3-tab tab control. On the 2nd tab page, there's a textbox named VehicleLocationName whose default value setting is ...
2
by: Bob | last post by:
I have a CreatedOn field , datetime, which has GetDate() as the default value in SQL server 2000 table. When I create a new record in the table itself in enterprise manager, the field gets...
2
by: windandwaves | last post by:
Hi Folk For input boxes in forms, some forms have default values e.g. "enter phone number here". When a user wants to enter their details, they first have to remove the default entry - which...
0
by: blabello | last post by:
Good morning, I've been tasked to create a series of self-validating composite controls using standard Visual Studio/AJAX controls and some custom-made validation controls. One of them is...
2
by: Erland Sommarskog | last post by:
lopina (ivica.lopar@email.t-com.hr) writes: I'm afraid I don't really get your problem. This is legal: create table ferenc (a int NULL DEFAULT NULL) Then again, even without an explicit...
7
by: jacc14 | last post by:
I have a main form with a quantity value and a continuous subform where i enter my line by line transactions. I want to set my default value for the quantity in the subform so it looks at the...
1
by: Eddie Z | last post by:
I'm trying to make a dialog box pop up and ask the User for their name when they open a particular form. I then want to set the default value of a text box called "EnteredBy" to their name. However...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.