Public Variable working with an InputBox

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

Guest

I have a large database that people enter user information for a computer
lab. What I want to do is make it so when the switchboard loads the user is
prompted to enter a date. Then they can click to access another form to enter
information into. The date is what I want to stay the same, from when they
enter it in at the main switch board in the InputBox. To the every new record
in that form. Whin the need to change the date they go back to the main
switch board. and start again.

*****This is what I have right now, for the switchboard. ******
Option Compare Database
Option Explicit
Public Dateall As String

*****On Activate for the switchboard****
Dim strInput As String
Dateall = "Enter a date like: 5/21/05"
strInput = InputBox(Prompt:=Dateall, Title:="Date")

*****This is what I thought would work for the form, but it does not work
Date is the name of the text box. Right now it is bound to the table.*****
Private Sub Form_GotFocus()
Date.Text = Dateall
End Sub


any help anyone???
Matt
 
Matt Roell said:
I have a large database that people enter user information for a computer
lab. What I want to do is make it so when the switchboard loads the user is
prompted to enter a date. Then they can click to access another form to enter
information into. The date is what I want to stay the same, from when they
enter it in at the main switch board in the InputBox. To the every new record
in that form. Whin the need to change the date they go back to the main
switch board. and start again.

*****This is what I have right now, for the switchboard. ******
Option Compare Database
Option Explicit
Public Dateall As String

*****On Activate for the switchboard****
Dim strInput As String
Dateall = "Enter a date like: 5/21/05"
strInput = InputBox(Prompt:=Dateall, Title:="Date")

*****This is what I thought would work for the form, but it does not work
Date is the name of the text box. Right now it is bound to the table.*****
Private Sub Form_GotFocus()
Date.Text = Dateall
End Sub


any help anyone???
Matt

Matt,

You said: "This is what I thought would work for the form, but it does
not work". From the text, we know what you want. But you did not
explain what is actually going wrong.

The only thing I can see is that Date.Text = Dateall probably needs to
be Date.Value = Dateall. I'm not quite sure why you'd want the text
box to display: "Enter a date like: 5/21/05".

When I ran the code with the alteration to .Value, nothing happend.
The GotFocus event never seemed to fire.


What I think you need is:


Public Dateall As String

Private Sub Form_Activate()
Dim strInput As String
Dateall = InputBox(Prompt:="Enter a date like: 5/21/05",
Title:="Date")
Date.Value = Dateall
End Sub

The above worked, and put whatever I entered into the InputBox into
the Text Box on the Form.

Note, this allowed me to enter "ae;lkfjasd;lkfj" into the date field.
You need some kind of validation in there. Maybe have Dateall be Date
data-type?


Sincerely,

Chris O.
 
Thanks Chris,

I tried the Date.Value = Dateall but my form didn't want to open with that.
I tried a few different things to the text box to make it display the date
that the user put in. But it seems like as soon as they(the users) open the
form the "date" is not put into the text box. It's just left empty. I'm not
sure if I have to make a code that will carrie the "date" over to the next
form that opens.

Matt
 
Matt Roell said:
Thanks Chris,

I tried the Date.Value = Dateall but my form didn't want to open
with that.

What do you mean by, "didn't want to open"?

I tried a few different things to the text box to make it display the date
that the user put in. But it seems like as soon as they(the users) open the
form the "date" is not put into the text box.

Please copy back here the code you *used* that didn't work.
 
*****Code from the main switchboard******
Private Sub Form_Activate()
Dim strInput As String
Dateall = InputBox(Prompt:="Enter a date like: 5/21/05", Title:="Date")
**Date.Text = Dateall *** (Did not work at all, I just got an error and it
told me to debug. )
End Sub

*****Code from the form with the text box*****
Private Sub Form_GotFocus()
Date.Value = Dateall
End Sub

Right now with this code. I can use enter any date in the InputBox and click
ok. But the when I open the form it does not put the date in the text box.

Thanks,
Matt
 
Matt Roell said:
*****Code from the main switchboard******
Private Sub Form_Activate()
Dim strInput As String
Dateall = InputBox(Prompt:="Enter a date like: 5/21/05", Title:="Date")
**Date.Text = Dateall *** (Did not work at all, I just got an
error and it

You can't do Date.Text = Dateall.

It must be Date.Value = Dateall.

In VBA, a Text Box's contents are accessed via the .Value property.
told me to debug. )
End Sub



*****Code from the form with the text box*****
Private Sub Form_GotFocus()
Date.Value = Dateall
End Sub

As I mentioned, in my tests, this event did not seem to fire. It
doesn't do anything because execution never runs over it.

Delete that portion of the code.

Change Date.Text to Date.Value.

Then try again.


Sincerely,

Chris O.
 
Back
Top