Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use a Form to input data vice the InputBox function?

Status
Not open for further replies.

hazlehurstga

Programmer
Sep 4, 2003
19
0
0
US
The following MSAccess 2000 VBA coding atempts to get input from the user by opening a form so the user can select from a combo list:
Code:
 ProcessingForm = True  
 DoCmd.OpenForm "ASSIGN CTPOC", , , , , acDialog
 Set LoadCTPOC = Forms("ASSIGN CTPOC")  
 LoadCTPOC.Visible = True
 Do While ProcessingForm
 Loop

The problem with the above coding is that it goes into the loop immediately after opening the form. The user is not given an opportunity to make a selection. NOTE: There is coding within the form itself that sets the global variable "ProcessingForm" to false after the user makes his selection.

What I am attempting to accomplish is to take advantage of the features available in a form to input a user's selection vice using the very limited features of the InputBox function. Also, the user will need to select from a list of options available, and, I don't believe the InputBox function will let the user choose from a list of options.

Can anyone help? Thanks
 
I am not very clear on what you are trying to do with your loop, as it contans no commands. If your trying to poll the value ProcessingForm while other things are going on,

Do While ProcessingForm

Loop

should be put in the timer event.

 
vbajock,
Thanks for your reply. The loop does nothing. Its purpose is to continually loop until the user makes his selection from the form LoadCTPOC. However, as I stated, the coding as described above does not allow the user to make a selection using the form. I need to present the user with a list of options, which the InputBox function does not permit. Can I use a form to get a user input vice using the InputBox function?
 
Do While ProcessingForm

Loop
is an infinite loop. It's going to stop everything from going on. You need to get rid of it or have something in the some other event to break you out of the loop.
 
vbajock,
Even without the loop, the coding described above does not let the user make a selection using the form. It simply opens the form then immediately executes the next line of coding. I need the program to wait or pause until the user has made his selection using the open form, then closed the form. Can this be done using a form or must I use the InputBox function, which does not permitt the user to select from a list of options?
 
The whole purpose of a form is to collect data, in about any way you can imagine. Things that prevent the collection of data:

Form is being opened in read only mode somehow. Check forms
Addtions, Deletion, and Edit property
Form is based on an un-updatable record set. Check your record source. Is it a read-only table? Is it a SQL that cannot be updated.
Code is stuck in a loop.

In an event driven environment, the form waits until you execute some type of event. You don't need any kind of code to accomplish this, it just does it. In its simplest form, the user enters data and clicks a button. When the button is clicked, something is done with the form or the data.


 
Understand. I apologize for not being very clear as to the problem I'm expericing but in a nut shell here's my problem:

my program gathers data from existing tables using VBA coding automatically untils it reaches a point where it needs data directly from the user. At this point, I could use the InputBox function to get the data from the user, but it won't work because I want the user to select from a list of options. So, I created a form with a a combo field that lets the user select from a list. However, when I use the VBA command DoCMD.OpenForm to open the form, the form opens, but execution continues within my program. I need the program to stop executing code somehow until the user has made his selection.
 
hazlehurstga,

I would recommend the following. Add a hidden, unbound field to your main form. Have he code open the inputform as above, but have the inputform place the response into the unbound box on the main form then close itself. Remove any and all code for the loop and the false/true stuff....

The main form will be opend and have a blank, hidden text box. The code will execute and at some point open the inputform and pause. The user makes a selection, which is placed into the blank text box, then the inputform closes. The code on the main form then continues and just reads from this text box for the chosen input.

****************************
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
I usually use an additional form to collect data, but you can probably try the following on a single form, because the idea is the same.

Set up a couple of functions in a code module, like this,

Public testval As Boolean

Function SetTestVal(ByVal testme As Boolean)
testval = testme
End Function

Function GetTestVal() As Boolean
GetTestVal = testval
End Function

in your processing loop, at the point you want to break your code:

Call SetTestVal(True)

'this is where I usually open a second form.

DoCmd.OpenForm "test"


Do

If GetTestVal() = False Then 'processing elsewhere is done

exit do 'to get out of this loop and back to processing

Else
'otherwise handle events elsewhere
DoEvents

End If

Loop



End Sub
 
Just to be clear, GetTestVal() needs to be set to false when the user has finished entering the data you need.
 
Thanks for your recommendations! I'll give it a try and let you know how it turns out.

hga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top