Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Type mismatch when copy empty cell to Access database

I got a code to write data from Excel to Access database, but got a "Type
mismatch" when copy cell B2 to "Dispatch_date" field in database, if B2 is
empty. The setting of "dispatch_date" in database requires no input. Please
help.

Sub ADOWritedata()

Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and
Settings\zi38610\Desktop\MIQ\Data\MIQ.mdb;"

Set rs = New ADODB.Recordset
rs.Open "Billing_Port_Forwarder_Charge", cn, adOpenKeyset,
adLockOptimistic, adCmdTable

r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
With rs
.AddNew ' create a new record
.Fields("Deal_number") = Trim(Range("A" & r).Value)
.Fields("Dispatch_date") = Trim(Range("B" & r).Value)
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Type mismatch when copy empty cell to Access database

Sub ADOWritedata()

Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and
Settings\zi38610\Desktop\MIQ\Data\MIQ.mdb;"

Set rs = New ADODB.Recordset
rs.Open "Billing_Port_Forwarder_Charge", cn, adOpenKeyset,
adLockOptimistic, adCmdTable

r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
With rs
.AddNew ' create a new record
.Fields("Deal_number") = Trim(Range("A" & r).Value)
if len(trim(Range("B" & r).Text)) 0 then _
.Fields("Dispatch_date") = Trim(Range("B" & r).Value)
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

--
Regards,
Tom Ogilvy

"Angus" wrote:

I got a code to write data from Excel to Access database, but got a "Type
mismatch" when copy cell B2 to "Dispatch_date" field in database, if B2 is
empty. The setting of "dispatch_date" in database requires no input. Please
help.

Sub ADOWritedata()

Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and
Settings\zi38610\Desktop\MIQ\Data\MIQ.mdb;"

Set rs = New ADODB.Recordset
rs.Open "Billing_Port_Forwarder_Charge", cn, adOpenKeyset,
adLockOptimistic, adCmdTable

r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
With rs
.AddNew ' create a new record
.Fields("Deal_number") = Trim(Range("A" & r).Value)
.Fields("Dispatch_date") = Trim(Range("B" & r).Value)
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Type Mismatch when running query on SQL Database Neily[_3_] Excel Programming 2 July 8th 05 02:21 PM
Database Query -- Data Type Mismatch StephenP Excel Discussion (Misc queries) 0 April 14th 05 07:05 PM


All times are GMT +1. The time now is 01:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"