Auto Fill Form Fields Type Mismatch Error

D

DaveAP

Using this method found on the boards below from Ofer Cohen to pre-fill some
fields onto a second form I get an error message "Type Mismatch":

You can pass the fields values using the OpenArgs, put a seperator between
them, like ($) Something that wont come up in the string

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If

Since the second form is a copy of the first, how is this possible? And how
to I assure this error won't come up?

Thank you in advance!!
 
B

Brendan Reynolds

DaveAP said:
Using this method found on the boards below from Ofer Cohen to pre-fill
some
fields onto a second form I get an error message "Type Mismatch":

You can pass the fields values using the OpenArgs, put a seperator between
them, like ($) Something that wont come up in the string

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the
open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If

Since the second form is a copy of the first, how is this possible? And
how
to I assure this error won't come up?

Thank you in advance!!


I haven't tested this, but my guess would be that the values are being
returned as strings, and that either Field1 or Field2 are non-text fields
(e.g. Number or Date/Time fields). If so, converting the values to the
appropriate data type should fix it. For example ...

'Assume, for example, that Field1 is a Long Integer ...
Me.Field1 = CLng(Split(Me.OpenArgs,"$")(0))
 
D

DaveAP

I had a missing comma in the string as well. And your suggestion patched the
rest of the it. Thanks!!

Brendan Reynolds said:
DaveAP said:
Using this method found on the boards below from Ofer Cohen to pre-fill
some
fields onto a second form I get an error message "Type Mismatch":

You can pass the fields values using the OpenArgs, put a seperator between
them, like ($) Something that wont come up in the string

DoCmd.OpenForm DocName, , , ,acFormAdd , ,Me.[Field1] & "$" & Me.[Field2]


On the OnLoad event of the second form form, write the code to split the
open
args and assign it to the text boxes

If Me.NewRecord Then
Me.[Field1] = Split(Me.OpenArgs,"$")(0)
Me.[Field2] = Split(Me.OpenArgs,"$")(1)
End If

Since the second form is a copy of the first, how is this possible? And
how
to I assure this error won't come up?

Thank you in advance!!


I haven't tested this, but my guess would be that the values are being
returned as strings, and that either Field1 or Field2 are non-text fields
(e.g. Number or Date/Time fields). If so, converting the values to the
appropriate data type should fix it. For example ...

'Assume, for example, that Field1 is a Long Integer ...
Me.Field1 = CLng(Split(Me.OpenArgs,"$")(0))
 

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