passing a value / type mismatch

  • Thread starter Thread starter DanielS
  • Start date Start date
D

DanielS

I know this question has been asked before because I have
read the responses and tried the suggestions, but I am
still stuck.
I have a series of 10 forms set up for gathering
information about a certain manufacturer. The user
enters the manufacturer's name on the first form and then
I want all of the following forms to display that name
(so it is very clear for my users what company they are
entering information for). So basically, I need to pass
the value to the next form and display it there. Please
help!
Below is the most recent trick I tried, but it didn't
work:
(I know it didn't work because on I never have a value
displayed on Form 2, and as soon as the AfterUpdate is
run on Form 1, I get a type mismatch error).

Form 1:

Option Compare Database

'Current Manufacturer variable
Dim strCurrMfr As String

Public Function CurrMfr() As String

'Public Function stores value of private variable
CurrMfr = strCurrMfr

End Function

Private Sub MfrName_AfterUpdate()
On Error GoTo Err_MfrName_AfterUpdate

'set Current Manufacturer Variable
strCurrMfr = Str(Me.MfrName.Value)

CurrMfr

Exit_MfrName_AfterUpdate:
Exit Sub

Err_MfrName_AfterUpdate:
MsgBox Err.Description
Resume Exit_MfrName_AfterUpdate

End Sub


Form 2:
I have an unbound text box where Control Source: =CurrMfr
()
 
Daniel,

Assuming Form1 calls Form2, and so on, why not just use the OpenArgs
argument of the OpenForm method:

DoCmd.OpenForm "Form2", , , , , , strCurrMfr

Then in Form2's Open method, you can retrieve the OpenArgs value:

strCurrMfr = Me.OpenArgs

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Graham,

Thank you so much! That was brilliant!
Another question...I also have a button to add a new
record. Any idea how to pass the same value and display
it on the new record? Since we aren't exactly opening a
new form, there aren't OpenArgs.

Thanks,
Daniel
 
Scratch that last request. I realized that you can still
access the forms OpenArgs when you go to the new record.
Thank you once again for you help.
 
Back
Top