Data Type Conversion Error

Little_Man22

Registered User.
Local time
Today, 16:32
Joined
Jun 23, 2001
Messages
118
I'm trying to copy a value from one field to another. It works through code like the following in the onload procedure of the second form:

Me!Income = Forms!frmClients!Income

I've got it to work, however, if the value is null I get the message 'Data type conversion error'. This only happens for numeric fields like income and net worth. A blank field doesn't affect other fields that are text. How can I change the code to get around this error when I have numeric fields?

Thanks, Ryan.
 
Try

Me.Income = Str(Forms!frmClients!Income)
 
It didn't seem to work jwindon...any other ideas?
 
OK. I missed the event.

Try OnCurrent instead of OnLoad.
 
Still not working.

I've trapped the error and it actually occurs in the code written for the command button which brings up the pop-up application (I put ** around the portion of the code where the error is occuring):

SaveRecord
Set rst = CurrentDb.OpenRecordset("SELECT * FROM ApplicationData WHERE PolicyID = " & Me!PolicyID)
With rst
If .EOF Then
.Close
DoCmd.OpenQuery "AddClientToApplication"
Else
Set rst2 = CurrentDb.OpenRecordset("qryClientPolicyApplicationData")
With rst
.Edit
For Each fld In rst2.Fields
strTest = Nz(rst2.Fields(fld.Name), " ")
**.Fields(fld.Name) = strTest**
Next fld
.Update
.Close
End With
rst2.Close
End If
End With
 
Wait a minute I think I missed the question entirely now! You are wanting to PASS the value from one form to another (Opening the form to match the previous)???

Now tell me that is what you want. This is so much simplar than what you are coding now.
 
Haha...yes you are correct when you say that I want to pass the value from one form to another. The code that I pasted came from a button on the origional form that opens the pop-up form (the pop-up form being where I want to pass the value to).

When I press this command button however, I get an error message 'Data Type Conversion Error'. And I know that it has to do with the income and networth fields being null (because when they are not null it works fine). I have trapped the error and it can be traced to the following line of code:

.Fields(fld.Name) = strTest

So my question is then: how can I make this line accept a null value?

Ryan.
 
Tweak this a bit. Make a dummy command button to try it. Save your code in case this doesn't suit you.

This code goes on the event to open the popup form:

DoCmd.OpenForm "frmApplicationData", acNormal, , , acFormEdit, , Me.PolicyID


This code goes on the OnLoad event of the second form:

If Not IsNull(Me.OpenArgs) Then

Me.PolicyID = Me.OpenArgs
End If
 
Hi again jwindon
smile.gif


The only problem is that the line in the code that is causing me problems occurs before the pop-up form is opened. Currently I use the following code (which I ommited from my origional cut and paste for berevity):

Select Case Me!Carrier
Case "Trans"
DoCmd.OpenForm "frmApplicationTrans"
Case "AIG"
DoCmd.OpenForm "frmApplication"
Case Else
MsgBox "No application for " & Me!Carrier
End Select

This is at the bottom of the code though for the command button...so I really think that somehow I need something to be written within the main body of code that will allow it to accept 'passed' null values. If it helps at all there are only 2 fields that needs to be passed that are causing me concern: networth and income.
 
Yes I tried it (or tweaked my code to add it). The problem is though that the line (DoCmd.OpenForm "frmApplicationData", acNormal, , , acFormEdit, , Me.PolicyID)
comes after the line of 'problem code' so Access never has a chance to reach it. That's what I mean when I say that something needs to written directly into my current code.

Ryan.
 
I think that I may have figured out a peice of the puzzle. The values in the fields income and networth get trapped in the code not because they are null, but rather because they are numeric zero-length strings. So now I have to figure out a way to set their values = to Null if they are empty.
 
Use the Nz() function to change the Null value to a 0.

RDH
 

Users who are viewing this thread

Back
Top Bottom