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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
On the ONLoad event of the form, write

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

Add a single quote before and after the variable
 
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.
 
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.

Ofer said:
On the ONLoad event of the form, write

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

Add a single quote before and after the variable

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


BGuidry said:
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.
 
I'm glad I could help

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


BGuidry said:
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.

Ofer said:
On the ONLoad event of the form, write

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

Add a single quote before and after the variable

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


BGuidry said:
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.
 
Back
Top