473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Cannot change a text box to blank with VBA

49
Stumped on another issue in Access 2003 (file format Access 2000) where code does not seem to do what it's supposed to based on other topics I have read.

I have a form that allows the user to select a record from the database's main list of properties when they determine that it matches a record on a new imported spreadsheet. (This requires a manual matching exercise, because several different data sources are to be blended together, and they do not all use the same names for the properties, etc. Needs to be rather user-friendly.)

Here is my code assigned to the On Change event for a combobox cboMatch:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboMatch_Change()
  2.  
  3.     ' Update the related field to the PropIndex of any selected property.
  4.  
  5.     If IsNull(cboMatch) Then       ' Deleting (un-matching) is an option.
  6.         txtPropIndex = Null
  7.         DoCmd.Save
  8.         txtPropIndex.Requery
  9.     Else
  10.         txtPropIndex = cboMatch
  11.         txtPropIndex.Requery
  12.     End If
  13.  
  14. End Sub
The form is Single Form view and bound to the new table, tblImportedFromAAPList(2). cboMatch is an unbound combobox and gets its row source from the main table, tblDCCProperties. txtPropIndex shows the value of PropIndex, the foreign key in the new table, which (after being matched) relates it to the main table.

The updating of txtPropIndex works absolutely fine if an option is selected from the list. However, I also want to make it possible to delete the value in cboMatch, which should then delete the value in txtPropIndex and the underlying table. (This option is a must in case an incorrect match is made.) And for some reason, txtPropIndex will not change to Null. Once a selection is made, it always shows a value; I cannot get it to delete, because it won't accept the Null from cboMatch and I have locked the control.

cboMatch is also programmed to show already-matched property names via On Current:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3.     ' If property is already matched when the record changes,
  4.     ' show the matched property name from tblDCCProperties in the combo box.
  5.  
  6.     If Not IsNull(txtPropIndex) Then
  7.         cboMatch = txtPropIndex
  8.     Else
  9.         cboMatch = ""                ' Otherwise, reset it to blank.
  10.         cboMatch.Requery
  11.     End If
  12.  
  13.     ' Regardless, the selectable field should be highlighted.
  14.  
  15.     cboMatch.SetFocus
  16.  
  17. End Sub
The second bit of code is working according to plan, as far as I can tell. I hope it isn't interfering with the problem code.

I've also tried "" rather than IsNull/= Null, and tried all of this with and without the DoCmd.Save, and even tested it out with On Dirty. The value in txtPropIndex will not ever go away.

Help? Please...?
Feb 17 '10 #1

✓ answered by TheSmileyCoder

DoCmd.Save will save your form not your record. You would need to use
docmd.RunCommand acCmdSaveRecord
to save the record.
Have you tried such a thing as:
Expand|Select|Wrap|Line Numbers
  1.     If IsNull(cboMatch) Then       ' Deleting (un-matching) is an option. 
  2.        msgBox "Running null match"
  3.         txtPropIndex = Null 
  4.         DoCmd.Save 
  5.         txtPropIndex.Requery 
  6.     Else 
  7.         txtPropIndex = cboMatch 
  8.         txtPropIndex.Requery 
  9.     End If 
So that you atleast know that the code is running.

Also is your textbox named the same as the field in your table? That can sometimes cause a bit odd results.

7 4047
TheSmileyCoder
2,322 Expert Mod 2GB
DoCmd.Save will save your form not your record. You would need to use
docmd.RunCommand acCmdSaveRecord
to save the record.
Have you tried such a thing as:
Expand|Select|Wrap|Line Numbers
  1.     If IsNull(cboMatch) Then       ' Deleting (un-matching) is an option. 
  2.        msgBox "Running null match"
  3.         txtPropIndex = Null 
  4.         DoCmd.Save 
  5.         txtPropIndex.Requery 
  6.     Else 
  7.         txtPropIndex = cboMatch 
  8.         txtPropIndex.Requery 
  9.     End If 
So that you atleast know that the code is running.

Also is your textbox named the same as the field in your table? That can sometimes cause a bit odd results.
Feb 17 '10 #2
JeremyI
49
Hmm... Okay, thanks, that was a good idea, TheSmileyOne. No message box appears; I also tried it for On Not in List, and still nothing. So I guess the events are not being triggered by deleting the text that displays in cboMatch.

The combobox has 2 columns, with Bound Column being 1, and widths of 0cm;1cm so that only the property's name displays for the user. The bound column is PropIndex, primary key in the main table of the database, but the combobox itself is unbound. Do you know if there is any event that would detect a user's deleting the display text in this combobox?

Regarding the name of the textbox ("txtPropIndex"), it is different from the field name ("PropIndex"), so that does rule out that potential issue.

Maybe I'll drop in a command button to "un-match".

But deletion would seem to be a simpler and more elegant solution if it's possible, so looking forward to any other suggestions!
Feb 18 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Have you tried using cmb_BeforeUpdate instead?

Maybe (I don't know) the cmb_Change is not triggered for unbound comboboxes? For instance the "Dirty" property of a firm is not triggered for unbound controls.
Feb 18 '10 #4
JeremyI
49
Thanks again, TSO, but alas, still nothing happens. I suppose this is all complicated because of the unbound combobox.

I think it has something to do with the fact that it is Column(1) of cboMatch that can be edited by the user. For instance, this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboMatch_Exit(Cancel As Integer)
  2.     If IsNull(cboMatch.Column(1)) Then txtPropIndex = Null
  3. End Sub
...does work as far as it goes. I.e., when I delete the text in cboMatch and move to a different control or click a navigation button, the value of txtPropIndex does get reset to Null.

However, there is an unfortunate side effect, in that I cannot navigate to another record while the focus is on cboMatch! I have to click on a different control before clicking any of the navigation buttons, or else the same record remains loaded. Seems very strange to me. But obviously I can't subject the data entry person to such nonsense.

Command button is now in place ("Remove Match") and although it seems a bit brutal, it does exactly what it needs to. I think I will stick with that option because as much as I personally would like to solve the problem properly, the needs of the project mean I mustn't dwell on cosmetics.

Appreciate your helpful thoughts very much!
Feb 18 '10 #5
NeoPa
32,556 Expert Mod 16PB
As Smiley says, consider a different event.

BeforeUpdate & AfterUpdate events would seem to fit most closely, though I'd only use BeforeUpdate if you are considering cancelling the change in your code. Otherwise (as I suspect), use AfterUpdate.
Feb 19 '10 #6
JeremyI
49
AfterUpdate is the one, NeoPa--cheers! I'm filing away this whole thread for future reference.
Feb 19 '10 #7
NeoPa
32,556 Expert Mod 16PB
Always a pleasure Jeremy.

Welcome to Bytes!
Feb 20 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Matt | last post by:
I was wondering if someone could explain why I'm receiving this error. It's like a 404 error but I think it might be something else. Basically, I have a page where a user inputs his email...
2
by: c duden | last post by:
I am able to add an exisiting office addin project to a blank solution in VS.NET 2003. When I attempt to add it's setup project I get the following error in VS.NET "Cannot change threading mode...
11
by: Yeah | last post by:
I have a multiple choice quiz where I would like to use CSS to change the color of the answers upon clicking them. I would like to present the right and wrong answers up front, rather than direct...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
5
by: J Huntley Palmer | last post by:
I am getting this error: Cannot modify header information - headers already sent by when I issue a header ("Location: http://www.foobar.com"); How can I redirect the user to such a site...
5
by: JEgbert | last post by:
I am trying to hide a layer when a text box length is zero, and its just not working! It hides the content in the layer, but you still see a little 2 pixel width blip on the screen. I've spent...
0
by: jianxin9 | last post by:
Hi everyone, I don't have a lot of experience with ASP and I was hoping someone could help me. I want to use our ASP form along with some javascript code to create a form where our patrons can...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
11
by: sajitk | last post by:
I am new to access and i am trying to build a database for enntering Subscription details of a particular journal. Wat I want is that FirstName field on the form should not be left blank. If the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.