dialog box to fill in text box in report

sasoderl

Board Regular
Joined
Feb 17, 2004
Messages
82
I would like to create one or more dialog boxes to use to fill in several text boxes in a report. I cannot find any information of how to do this using MS Help function nor in any book I have. Does anyone know if this is possible and if so, how can I attempt it?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You probably want to use the inputbox method. It has the syntax: InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])

So you could do something like:

Code:
Function TestInputbox()
Dim var1
var1 = InputBox("Enter a Value!", "Test")
MsgBox var1, vbOKOnly, "Value from InputBox"
End Function

But for the report you would set the inputbox equal to the report field.

HTH,
CT
 
Upvote 0
Just curious (this may seem like a stupid question), how do I get the input box to "pop up" and where would I write the VB code?
 
Upvote 0
Access "knows" to have the input box as a dialog box that pop-up.

you would put the code in the reports ON_Open event. Go to the report properties window and find the On Open. If you select this you will see the elipse (...) appear. Click on this and another dialog will open asking "Choose Builder". Select "Code Builder" Paste the code. This will now run everytime you open the report.


To test this code. Go to Module-> New. Paste the code and run(F5).

HTH,
CT
 
Upvote 0
Thanks for your help. I have one more (hopefully only one more) question for you. I have a field in my report called DateField, when I set the inputBox = to the DateField and try testing the code, it doesnt appear in the field. And actually, the field is a label. Could this be my problem?

Here is the code (only slightly modified as of now while testing):

Private Sub Report_Open(Cancel As Integer)

Dim DateField
DateField = InputBox("Enter a Value!", "Test")
MsgBox DateField, vbOKOnly, "Value from InputBox"
End Sub

Have any ideas??
 
Upvote 0
Ok, Here is a different approach.

Remove everything from the On_Open event.

In the report code/module add the following:

Code:
Function AddInputBoxText() As String
AddInputBoxText = InputBox("Enter a Value!", "Test")
MsgBox AddInputBoxText, vbOKOnly, "Value from InputBox"
End Function

Now on your field (must be textbox) that you want to place the data, make the control source something like:

="Report Period From" & " " & AddInputBoxText()

Now run your report. You should get the input box, then the msgbox, then the textbox on your report should say Report Period From (inputbox text).

HTH,
CT
 
Upvote 0
Hey, that was great! Thank you very much. I have one more question for you (for real this time)! I have two fields on each page of each report that require the same input data (specifically, the date field) Is there a way to have them both fill in without the function for the input box being called twice to fill the date in?

Thanks again
 
Upvote 0
To do this reference the first textbox from the second. IE textboxes are named text0 and text1

text0="Report Period From" & " " & AddInputBoxText()

text1=[text0]

HTH,
CT
 
Upvote 0
Unfortunately, that did not solve the problem. It references the text box which calls the function, therefore, the function is still being called twice. I wonder, do I need to create a variable and store the value???
 
Upvote 0
Something else is probably running. Check to make sure that you aren't calling the function twice by using on_open or other methods.

HTH,
CT
 
Upvote 0

Forum statistics

Threads
1,221,687
Messages
6,161,289
Members
451,695
Latest member
Doug Mize 1024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top