Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

Can I put a public variable into a default on a form?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BGuidry - 16 Jan 2006 16:59 GMT
I use the following coding to keep a salesman name for entry into a order
entry system:
Public gstrThisUser As String
Is there a way to move that variable into the default value on a form? I
have got coding to work with a interger value but cannot get it to work with
a string value. Thanks for any help.
Jim Burke in Novi - 16 Jan 2006 17:10 GMT
I assume you mean you want a control on the form to have that as the default
value. I don't know if you can assign a variable's value a control's default
value property , but you can set the value of the control to that value in
your Form Open event procedure, e.g. if your control is a textbox called
txtA...

Private Sub Form_Open(Cancel As Integer)

  txtA.value = gstrThisUser

End Sub

Hope this helps.

> I use the following coding to keep a salesman name for entry into a order
> entry system:
> Public gstrThisUser As String
> Is there a way to move that variable into the default value on a form? I
> have got coding to work with a interger value but cannot get it to work with
> a string value. Thanks for any help.
BGuidry - 16 Jan 2006 17:30 GMT
Jim below is the coding which is similar to yours that I am using:
Me.SalesmanName.DefaultValue = gstrThisUser
The only problem is that it returns a error. If I use a interger field
instead it will work just fine. I have tried just about everything and it
seems the problem is that it needs "" in front and behind the variable. So if
you or any one else can help with that I would greatly appreciate it.

> I assume you mean you want a control on the form to have that as the default
> value. I don't know if you can assign a variable's value a control's default
[quoted text clipped - 16 lines]
> > have got coding to work with a interger value but cannot get it to work with
> > a string value. Thanks for any help.
Ofer - 16 Jan 2006 18:07 GMT
Have you tried my suggestion?

Me.SalesmanName.DefaultValue = "'" & gstrThisUser & "'"

Signature

\\// Live Long and Prosper \\//
BS"D

> Jim below is the coding which is similar to yours that I am using:
> Me.SalesmanName.DefaultValue = gstrThisUser
[quoted text clipped - 23 lines]
> > > have got coding to work with a interger value but cannot get it to work with
> > > a string value. Thanks for any help.
Ofer - 16 Jan 2006 17:20 GMT
On the ONLoad event of the form, write

Me.[FieldName].DefaultValue = "'" & VariableName & "'"

Add a single quote before and after the variable

Signature

\\// Live Long and Prosper \\//
BS"D

> I use the following coding to keep a salesman name for entry into a order
> entry system:
> Public gstrThisUser As String
> Is there a way to move that variable into the default value on a form? I
> have got coding to work with a interger value but cannot get it to work with
> a string value. Thanks for any help.
BGuidry - 16 Jan 2006 19:49 GMT
Thanks Ofer that did the trick. I thought I had tried that one but I guess I
was wrong. It has been awhile since I have done anything in Access so it is
nice to know there is somewhere to turn when I run into a stumper.

> On the ONLoad event of the form, write
>
[quoted text clipped - 8 lines]
> > have got coding to work with a interger value but cannot get it to work with
> > a string value. Thanks for any help.
Ofer - 16 Jan 2006 20:07 GMT
I'm glad I could help

Signature

\\// Live Long and Prosper \\//
BS"D

> Thanks Ofer that did the trick. I thought I had tried that one but I guess I
> was wrong. It has been awhile since I have done anything in Access so it is
[quoted text clipped - 12 lines]
> > > have got coding to work with a interger value but cannot get it to work with
> > > a string value. Thanks for any help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.