Solved

Data type conversion error on update query

Posted on 2009-05-16
7
679 Views
Last Modified: 2013-12-25
I have an subform in a tab control that used two combo boxes to pick values from a query.  The vales are then used in an update query to a table.

The update query runs perfectly when run from the form itself, however when I run the update query from within the form within a tab control I get "didn't update ##field(s) due to a data type conversion error".  The fields are all text and the lengths are the same.  Why would this run right from the form but give the error when the same form is embedded in a tab control?

If I ignore the error and click though it changes all the data in the AgentName field to a nul value.

I have tried sending the combo box values to text boxes and also to global variables but still get the same error when update is run from within the tab control.

- Many thanks in advance...
"UPDATE Sales_Tracking SET Sales_Tracking.AgentName = " & _
"Replace([AgentName],Forms!frm_Administration!tabctrl_Admin!cmbOldAgent, " & _
"Forms!frm_Administration!tabctrl_Admin!cmbNewAgent);"

Open in new window

0
Comment
Question by:ehorde
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:paisleym
ID: 24404618
Hi

What is the query underlying those combo boxes? i.e. Both controls are returning the agents name in the first column? What if there is no new agent name selected yet (i.e. resulting in a null value)?

Marcelle
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 24404928
Try changing the query to this.
"UPDATE Sales_Tracking " & _
"SET Sales_Tracking.AgentName = '" & Forms!frm_Administration!tabctrl_Admin!cmbNewAgent & "' " & _
"WHERE Sales_Tracking.AgentName = '" & Forms!frm_Administration!tabctrl_Admin!cmbOldAgent & "';"

Open in new window

0
 

Author Comment

by:ehorde
ID: 24412587
paisleym - There are two separate and very simple query that simply grab the AgentName for use as Original and the Replacement values.  

jimpen - Set instead of Replace? I will try that.

On a note, If I make the subform PopUp and Modal and call it from a command button in the tabcontrol all works without changing any of the query's code I just wanted to keep everything in the tabs instead of adding more forms that popup.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 38

Expert Comment

by:Jim P.
ID: 24413080
You should be able to from a button. In fact -- that is the common way of doing it.
0
 

Author Comment

by:ehorde
ID: 24436512
jimpen - I tested your suggestion and it seems to "run", although it says "About to update "0" rows" in a message box where there should be dozens of records.  I will tweek it some more.
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 24436546
Can we see the surrounding code?
0
 

Accepted Solution

by:
ehorde earned 0 total points
ID: 24436986
I created a subform call "subfrm_LeadReassign_Admin" and placed that into the tabcontrol and then
placed all the controls into the subform and that fixed it.  Making the subform flat and the borders transparent makes it appear to be directly on the tab itself.

I skipped referencing the tabcontrol in the update query and referenced the subform directly.

As you can see I also added a join for some other filtering too.

I can't explain it, I am a beginner at this stuff.
UPDATE Sales_Tracking INNER JOIN Projects ON Sales_Tracking.CommunityInterestedIn = Projects.Project_Key SET Sales_Tracking.AgentName = Forms!frm_Administration!subfrm_LeadReassign_Admin!cmbNewAgent
WHERE (((Sales_Tracking.AgentName)=[Forms]![frm_Administration]![subfrm_LeadReassign_Admin]![cmbOldAgent]) AND ((Projects.ProjectName) Like [Forms]![frm_Administration]![subfrm_LeadReassign_Admin]![cmbProjectFilter] & "*"));

Open in new window

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question