SAVING Basic User Input (for use elsewhere)

  • Thread starter kev100 via AccessMonster.com
  • Start date
K

kev100 via AccessMonster.com

I'm just beginning to how to use earn VBA programming with Access. Up to
this point....I've gotten by with creating Access queries, macors, etc.

I'm needing to simply have a popup box that accepts user input (e.g. Input
First Name:) save it to a variable...and then be able to reference that
variable in other forms, queries, etc. The information will generally NOT
need to be permantely saved. When the app is exited...it's okay if it goes
away.

I'm assuming that there is no "User Input Popup Wizard" in Access...so
creating code to do this is the only option.

The following code was suggested in another forum...

Option Compare Database
Public gbl_UserInput As String
Option Explicit

Dim strInput As String
Dim strMsg As String

strMsg = "Input First Name:"

strInput = InputBox(Prompt:=strMsg, title:="First Name")
gbl_UserInput = strInput


To test, I create a form with 1 button. Then select the button's properties
and then Event/On Click / ... and enter the above code.

On running the form and entering clicking the button....the error occurs:

Compile Error
Invalid Inside Procedure

....and the "Option Compare Database" line is highlighted.

I've tried a little guess-editing here and there...but simply can't get it to
run. I can't help thinking it must be some simple issue as this has to be a
really common function.

Thanks
 
J

John Vinson

I'm needing to simply have a popup box that accepts user input (e.g. Input
First Name:) save it to a variable...and then be able to reference that
variable in other forms, queries, etc. The information will generally NOT
need to be permantely saved. When the app is exited...it's okay if it goes
away.

Rather than using an inputbox and a variable, I'd suggest simply using
a Form with textboxes (or combo boxes or other controls) into which
the user can enter or select the desired values.

Other Forms, Queries, and Reports can reference

=Forms![NameOfTheForm]![NameOfTheControl]

so long as the form stays open.

John W. Vinson[MVP]
 
K

kev100 via AccessMonster.com

COOL !....that looks like it's working....and leading to some other very
handy functions as well. Thanks!

What I've done is to create a form which has a text box into which the user
enters data.

I have an existing form created based on a query. The query references the
data entered in that text box to perform a calculation.

I placed a button on this new form (with the text entry box) that will open
that existing form when clicked.....so...the user can open this new form,
make an entry, click the button....and the other form pops ups with the info
and updated calculations based on what they just entered.

I noticed that you can embed a form into a form (called subforms?)....so that
when the form is opened.....the other embedded form is displayed as well....
very cool.

HOWEVER.....when I do this....and the user clicks the button after entering
data into into the box...the form that is embedded pops up in a window (with
the update results). The data on the embedded instance of that form does not
change.

It would be great if only the embedded form were visable when clicking that
button.....and if different data were entered in text box above....clicking
the button would update the values in the embedded view of the existing form
(sort of refreshing it...since that form is based on a query that references
the data entered)

Is anything like this possible?

Thanks very much.
 
J

John Vinson

It would be great if only the embedded form were visable when clicking that
button.....and if different data were entered in text box above....clicking
the button would update the values in the embedded view of the existing form
(sort of refreshing it...since that form is based on a query that references
the data entered)

It's even simpler than that.

You don't need the button, or even any VBA code AT ALL!

Simply make the user's textbox the Master Link Field of the subform,
and the corresponding field in the table upon which the subform is
based the Child Link Field. The Subform's recordsource should contain
all the records which might match.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top