Type Mismatch error when entering data into access database from excel using userform

sathyaganapathi

Board Regular
Joined
Apr 29, 2021
Messages
81
Office Version
  1. 2016
Platform
  1. Windows
I am entering data into userform and want to store the data in access database.
I am getting 'Type mismatch' error (run_time error '-2147352571(80020005)' while running the program and the error is pointing out to the below code.
If I enter the date into userform field I am not getting the error and data is saved into access database.
I have not entered any date to the field. It is left blank. There are several date and time fields which will be filled at different time. I cannot enter date into all the fields together.

VBA Code:
[CODE]rst.Fields("Route_Time").Value = CDate(Plab_Update.RouteTime.Value)
[/CODE]
VBA Code:
rst.Fields("H1_Release_DateTime").Value = CDate(Plab_Update.Release1Date.Value)

I tried with below two codes and did not help.

VBA Code:
[CODE]rst.Fields("Route_Time").Value = VBA.Format(Plab_Update.RouteTime.Value, "HH:mm")
[/CODE]
VBA Code:
[CODE=vba]rst.Fields("Route_Time").Value = VBA.Format(Plab_Update.RouteTime.Value, "HH:nn")
[/CODE]

The field "Plab_Update.RouteTime" and "Plab_Update.Release1Date" are set with below format.
VBA Code:
[CODE]Plab_Update.RouteTime.Value = VBA.Format(Now(), "HH:mm")
[/CODE]
VBA Code:
Plab_Update.Release1Date.Value = VBA.Format(Now(), "mm/dd/yyyy HH:mm")

In other VBA code I have used the above code (1st one) and it is working well.
Please help with some solution.
 
is your form bound?
Untested, but for your date/time fields try

rst.Fields("Reading_By").Value = Plab_Update.ReadingBy.Value
rst.Fields("Reading_Time").Value = "#" & CDate(Plab_Update.ReadingTime.Value) & "#"
rst.Fields("SAP_Entry_By").Value = Plab_Update.SAPEntryBy.Value
rst.Fields("SAP_Entry_Time").Value = "#" & CDate(Plab_Update.SAPEntryTime.Value) & "#"
rst.Fields("Lot_Cleared_By").Value = Plab_Update.LotClearedBy.Value
rst.Fields("Lot_Cleared_DateTime").Value = "#" & CDate(Plab_Update.LotClearDateTime.Value) & "#"
Hi jackd,
good morning.
the form is unboud i believe... I mean, I am using the excel userform and excel VBA.

I tried with the code you provided like below
"rst.Fields("Reading_Time").Value = "#" & CDate(Plab_Update.ReadingTime.Value) & "#""
Still error 13 type mismatch is observed on the same line.
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
is your form bound?
Untested, but for your date/time fields try

rst.Fields("Reading_By").Value = Plab_Update.ReadingBy.Value
rst.Fields("Reading_Time").Value = "#" & CDate(Plab_Update.ReadingTime.Value) & "#"
rst.Fields("SAP_Entry_By").Value = Plab_Update.SAPEntryBy.Value
rst.Fields("SAP_Entry_Time").Value = "#" & CDate(Plab_Update.SAPEntryTime.Value) & "#"
rst.Fields("Lot_Cleared_By").Value = Plab_Update.LotClearedBy.Value
rst.Fields("Lot_Cleared_DateTime").Value = "#" & CDate(Plab_Update.LotClearDateTime.Value) & "#"
Hi jackd,
btw, can I use "On Error Resume Next". what is the implication of this in the code?
I tried this and when date is not entered, the other data are getting saved. I s there any other problems anticipated from this?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top