runtime error 3464 data type mismatch (1 Viewer)

dcmphi

Registered User.
Local time
Today, 22:01
Joined
Sep 30, 2016
Messages
10
I have table with 4 field (1) ID (Primary Auto Increment) (2) TDate (3) BillNO (4) Taka (5) Vat and i have a form with text box "txtID", "txtTDate", "txtBillNo", "txtTaka", "txtVat" an a update button. I want to update record through the from with event procedure. i use the following code to update the record but i got an error "runtime error 3464 data type mismatch" Can anyone help me
<code>
CurrentDb.Execute "UPDATE tblTransaction " & _
" SET [TDate] = '" & Me.txtTDate & "'" & _
", [BillNo] = " & Me.txtBillNo & "" & _
", [TotalTaka] = " & Me.txtTotalTaka & "" & _
", [Vat] = '" & Me.txtVat & "'" & _
" WHERE [ID] = ' " & Me.txtID.Tag & " '"
</code>
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:01
Joined
May 7, 2009
Messages
19,169
If tdate is date/time data type:

CurrentDb.Execute "UPDATE tblTransaction " & _
" SET [TDate] = #" & Format(Me.txtTDate, "mm/dd/yyyy") & "# " & _
", [BillNo] = " & Me.txtBillNo & _
", [TotalTaka] = " & Me.txtTotalTaka & _
", [Vat] = " & Me.txtVat & _
" WHERE [ID] = " & Me.txtID.Tag
 

dcmphi

Registered User.
Local time
Today, 22:01
Joined
Sep 30, 2016
Messages
10
Thank you @arnelgp for reply. I want to format my BillNo as "123/1245" How can i do this format.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:01
Joined
May 7, 2009
Messages
19,169
Yiu need to edit the table and form put input mask 000\/0000
 

dcmphi

Registered User.
Local time
Today, 22:01
Joined
Sep 30, 2016
Messages
10
Thanks @arnelgp.

How to insert too many fields like
<code>
CurrentDb.Execute "INSERT INTO tblContactData ([RecordType],[FISubjectCode],[FIContractCode],[ContractType],[ContractPhase],[ContractStatus],[CurrencyCode],StartingDate],[RequestDate],[PlannedEndDate],[ActualEndDate],[DefaultStatus],[DateofLastPaynt],[FlagSubsidizedCredit],[FlagPreFinanceofLoan],[CodeReorganizedCredit],[ThirdPartyGuaranteeType],[SecurityType],[AmountGuaranteed],[AmountGuaranteedSecuritTtype],[BasisForClassification],[SanctionLimit],[TotalOutstanding],[DayntDelay],[OverdueAmount],[ReportingPeriod],[CumulativeRecovery],[DateOfLawSuit],[DateOfClassification],[NoTiRescheduling],[DateOfLastReschedul],[EconomicPurposeCode],[SME],[EnterpriseType],[TypeOfLink],[FIPrimaryCode],[FISecondaryCode],VALUES ('" & Me.RecordType& "','" & Me.FISubjectCode& "','" & Me.FIContractCode& "','" & Me.ContractType& "','" & Me.ContractPhase& "','" & Me.ContractStatus& "','" & Me.CurrencyCode& "',StartingDate& "','" & Me.RequestDate& "','" & Me.PlannedEndDate& "','" & Me.ActualEndDate& "','" & Me.DefaultStatus& "','" & Me.DateofLastPaynt& "','" & Me.FlagSubsidizedCredit& "','" & Me.FlagPreFinanceofLoan& "','" & Me.CodeReorganizedCredit& "','" & Me.ThirdPartyGuaranteeType& "','" & Me.SecurityType& "','" & Me.AmountGuaranteed& "','" & Me.AmountGuaranteedSecuritTtype& "','" & Me.BasisForClassification& "','" & Me.SanctionLimit& "','" & Me.TotalOutstanding& "','" & Me.DayntDelay& "','" & Me.OverdueAmount& "','" & Me.ReportingPeriod& "','" & Me.CumulativeRecovery& "','" & Me.DateOfLawSuit& "','" & Me.DateOfClassification& "','" & Me.NoTiRescheduling& "','" & Me.DateOfLastReschedul& "','" & Me.EconomicPurposeCode& "','" & Me.SME& "','" & Me.EnterpriseType& "','" & Me.TypeOfLink& "','" & Me.FIPrimaryCode& "','" & Me.FISecondaryCode& "')"
</code>
 

Minty

AWF VIP
Local time
Today, 15:01
Joined
Jul 26, 2013
Messages
10,354
This looks like an unbound form. To make this more readable and usable I would use a parameter query this will also remove the need for complicated string formatting - the syntax is along the lines of;

Code:
const SQL_INSERT as string = _
   "INSERT INTO tTable " & _
      "( numField, strField, datField ) " & _
   "VALUES " & _
      "( p0, p1, p2 ) "

with currentdb.createquerydef("", SQL_INSERT)
   .parameters("p0") = 123
   .parameters("p1") = "test"
   .parameters("p2") = #3/7/17#
   .execute dbFailOnError
   .close
end with
Or save the query then use that like this;
Code:
Set db = CurrentDb
Set qdf = db.QueryDefs("SavedQueryName")

' BIND VALUES TO PARAMETERS
qdf.Parameters("Parameter1") = Me.cmbFirstParam
qdf.Parameters("Parameter2") = Me.txtboxSecondParam 
qdf.Parameters("Parameter3") = Me.ListBoxParam3
etc, etc

Set rst = qdf.OpenRecordset
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:01
Joined
May 7, 2009
Messages
19,169
I wrote a function sometimes ago, same as with minty's code, fnAnySQL().
https://www.access-programmers.co.uk/forums/showthread.php?t=297170&highlight=Fnanysql

copy and paste it in a Module:

then you need only to call it:

Call fnAnySQL( _
"INSERT INTO tblContactData ([RecordType],[FISubjectCode],[FIContractCode],[ContractType],[ContractPhase],[ContractStatus],[CurrencyCode],StartingDate],[RequestDate],[PlannedEndDate],[ActualEndDate],[DefaultStatus],[DateofLastPaynt],[FlagSubsidizedCredit],[FlagPreFinanceofLoan],[CodeReorganizedCredit],[ThirdPartyGuaranteeType],[SecurityType],[AmountGuaranteed],[AmountGuaranteedSecuritTtype],[BasisForClassification],[SanctionLimit],[TotalOutstanding],[DayntDelay],[OverdueAmount],[ReportingPeriod],[CumulativeRecovery],[DateOfLawSuit],[DateOfClassification],[NoTiRescheduling],[DateOfLastReschedul],[EconomicPurposeCode],[SME],[EnterpriseType],[TypeOfLink],[FIPrimaryCode],[FISecondaryCode] SELECT @1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,@24,@25,@26,@27,@28,@29,@30,@31,@32,@33,@34,@35,@36,@37", _
Me.RecordType,Me.FISubjectCode,Me.FIContractCode,Me.ContractType,Me.ContractPhase,Me.ContractStatus,Me.CurrencyCode,StartingDate,Me.RequestDate,Me.PlannedEndDate,Me.ActualEndDate, Me.DefaultStatus,Me.DateofLastPaynt,Me.FlagSubsidizedCredit,Me.FlagPreFinanceofLoan,Me.CodeReorganizedCredit,Me.ThirdPartyGuaranteeType,Me.SecurityType,Me.AmountGuaranteed,Me.AmountGuaranteedSecuritTtype,Me.BasisForClassification,Me.SanctionLimit,Me.TotalOutstanding,Me.DayntDelay,Me.OverdueAmount,Me.ReportingPeriod,Me.CumulativeRecovery,Me.DateOfLawSuit,Me.DateOfClassification,Me.NoTiRescheduling,Me.DateOfLastReschedul,Me.EconomicPurposeCode,Me.SME,Me.EnterpriseType,Me.TypeOfLink,Me.FIPrimaryCode,Me.FISecondaryCode)
 

missinglinq

AWF VIP
Local time
Today, 11:01
Joined
Jun 20, 2003
Messages
6,423
How to insert too many fields like...

Why are you using an Unbound Form?

Using Unbound Forms really does away with the basic function of Access, which is to facilitate RAD (Rapid Application Development) and should only be attempted by very experienced Access developers, and then only when/if a legitimate purpose requires it, and most situations don’t! You don't need Unbound Forms to

  1. Do Data Validation
  2. Prevent Duplicate Records
  3. Do Formatting of Data before it's Saved
  4. Decide whether or not to actually Save a New or Edited Record

which are the most common reasons given. Nor are they needed for another dozen reasons I've seen people give!

Several developers I know, experienced in Visual Basic database development and Access development, estimate that development, using Unbound Forms, by highly experienced developers, takes two to three times as long, using Unbound Forms, as it does when using Access and Bound Forms. That’s because with Bound Forms the Access Gnomes do the vast majority of the heavy lifting; with Unbound Forms the developer has to write code for everything...even the most mundane tasks!

Bottom line is…with Bound Forms you end up writing code for a few specialized situations, such as #1-#4, as listed above…and with Unbound Forms you have to write code for virtually everything that needs to be done!

If you insist on using Unbound Forms, you'd be far better off using a straight VB or C++ front end with a SQL Server or Oracle back end.

  • You can create an EXE file which gives total protection to your code/design
  • You can distribute the db to PCs without a copy of Access being on board
  • Your data security is far, far better than anything you can do in Access

Don't misunderstand me...there are a few, specialized situations, where an Unbound Form is preferable...but anyone who routinely uses them for everything, has simply made a bad choice in deciding to work in Access.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom