2

I am trying to import fields from a form field word document I have created into a MS-Access table. The import works fine unless there is a null in one of the date fields, and then it throws a type mismatch error. How do I keep from getting this error?

Dim rst As New ADODB.Recordset
With rst
    .AddNew
    !BPRid = doc.FormFields("frmBPRid").Result
    If Not IsNull(doc.FormFields("frmReceiptDate").Result) Then
    !ReceiptDate = doc.FormFields("frmReceiptDate").Result
    End If    
    .Update
    .Close
End With

I tried wrapping it in an if statement as seen above, but it seems it doesn't recognize the field as null. Any help would be appreciated. Thanks in Advance.

1 Answer 1

3

I suspect it is probably a zero length string ("").

You might like to use IsDate.

If IsDate(doc.FormFields("frmReceiptDate").Result) Then
   !ReceiptDate = doc.FormFields("frmReceiptDate").Result
End If   

For other data types, you can check for a zero length string and space filled fields like so:

If Trim(doc.FormFields("frmReceiptDate").Result & "") <> vbNullString
6
  • This may need to be another question, but is there any way to determine if a field exists on the form?
    – talbright
    Jul 23, 2012 at 15:28
  • You could certainly check through the form fields. Let me see if there is a quicker way.
    – Fionnuala
    Jul 23, 2012 at 15:30
  • There seems to have been a considerable change in the way forms work between Access 2003 and 2007. You will need to ask about the version you are using.
    – Fionnuala
    Jul 23, 2012 at 16:03
  • What do you mean by check through the form fields? The reason I'm asking is because, I have multiple related form field documents and I would like to reuse the same module for all of them.
    – talbright
    Jul 23, 2012 at 16:03
  • 1
    That is where the version comes in, for example, in word 2010, you can use For Each ctl In ActiveDocument.ContentControls whereas for Word 2000, you have support.microsoft.com/kb/212405
    – Fionnuala
    Jul 23, 2012 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.