473,396 Members | 2,147 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,396 software developers and data experts.

ComboBox problem: choosing item 'dirties' the form, so won't move off record

I was scolded on "Bytes" a couple of weeks back for writing all my own Save/Delete/Next etc buttons, so I have completely redone my main "Contacts" form using the button wizard. (I've also converted all the Macros to VBA so that I can more or less understand what they are actually doing!) Must admit this has cleaned things up a lot, but I have hit a problem ... as follows

There is an unbound "Find Contact" combo box on the form which lists all the Contact last names, where the user USED TO be able to pick a surname, and have that record appear on the form. There is code behind this which says "if the form isn't dirty, display new record for the name chosen". However, NOW this doesn't work because the action of choosing a name off the list "dirties" the form and Access won't move to a new record if the form is dirty. (If I take out the "If not dirty ..." bit of code, it just crashes - of course!)

I can think of some revolting possible ways around this, but it seems such an obvious sort of problem there's probably an obvious and simple solution which all you guys will know about????
Feb 11 '10 #1
7 2131
Replying to myself!

I solved this problem in the wee small hours after rather a lot of alcohol! The solution may be useful to someone else, and anyway it will stop you bothering to answer the question.

You need to 'clean' the FindContact combo-box after the selection has been made ... so store the ContactID in a local variable, set the combo-box back to its old value, and THEN find the new record. Here's the code ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub FindContactCombo_Change()
  2.     Dim contID As Long
  3.     Dim pos As Integer
  4.     pos = Me.FindContactCombo.ListIndex
  5.     If pos <> -1 Then
  6.             'save the ContactID in the var contID
  7.         contID = Me.FindContactCombo.Column(0, pos)
  8.             'reinstate the old value for FindContactCombo,
  9.             'so that this field is 'clean'
  10.         Me.FindContactCombo.Value = Me.FindContactCombo.OldValue
  11.            'if no other changes have been made ...
  12.         If Not (Me.Dirty) Then
  13.                'bookmark the record for contID
  14.             Dim rst As Recordset
  15.             Set rst = Me.RecordsetClone
  16.             rst.FindFirst "ContactID = " & contID
  17.                 If rst.NoMatch Then
  18.                     MsgBox "Record not found"
  19.                 Else
  20.                     Me.Bookmark = rst.Bookmark
  21.                 End If
  22.             rst.Close
  23.         Else
  24.                'changes have been made to the current record
  25.             MsgBox ("Please either save or cancel the changes " _
  26.                 & "you've made before moving away from this Contact.")
  27.         End If
  28.     End If
  29. End Sub
  30.  
Sorry to have bothered you with this. I'm very grateful for all the help I've had from Bytes, as now the code behind this ContactForm is about 1/4 of what it was before when I was coding all the buttons myself, and about 4 times more comprehensible/maintainable.
Feb 12 '10 #2
ADezii
8,834 Expert 8TB
Forgive me if I am not correct in my assumption, but I do not think that selecting a Value in an 'Unbound' Combo Box will Dirty the Form.
Feb 12 '10 #3
That's EXACTLY what I thought. It really is unbound, but the row source is using the same table as the one the form is bound to ... i.e. the records for the form are the "Contacts" from the CONTACT_table, and the row source for the ComboBod is "SELECT ContactId, FamilyName FROM CONTACT_table". Is that the problem? I feel SURE that in the dim-distant past I didn't have this problem, but it was 10 years ago, so maybe I've just forgotten about it!

It's annoying, actually, because altho' my solution "works" it doesn't quite ... Obviously it precludes the user typing in the first few letters and getting the name "predicted", so he/she has to scroll down the combo-box ... I'm still pondering on whether there's another solution. Any thoughts? Or maybe your "thoughts" will be that I've just done something dumb ... I hope so!
Feb 12 '10 #4
ADezii
8,834 Expert 8TB
You could dynamically populate a Temporary Table from the 2 Fields from the Contacts Table, then use that as the Source for the Combo Box.
Feb 12 '10 #5
Yes, thank you, that's a good idea, and I'll probably end up doing that. It just seems a bit labour intensive, doesn't it!
Feb 13 '10 #6
ADezii
8,834 Expert 8TB
It just seems a bit labour intensive, doesn't it!
Yes, but if you current solution does not agree with you, then it is simply a matter of priorities.
Feb 13 '10 #7
Yup! Done it! (I sometimes feel like I'm back at school ... these gentle reprimands!)
Feb 13 '10 #8

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

Similar topics

1
by: Oren Kaplan | last post by:
Hello, I posted a msg on the Access-related groups in hope someone there could help me but since almost two days have past and I didnt get a response (Im a bit hard pressed with the problem) I...
2
by: Phil | last post by:
My form uses a dataset containing two tables, a base table (Contact) and a lookup table (Insurer). My combobox is bound as follows: DataSource = datasetContact DisplayMember =...
6
by: Rey | last post by:
Howdy, all. Appreciate your help. Have a one to many relation between a client and visit table. In the visit subform, I have a visittype and counselor field which are comboboxes. If I set...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
4
by: Rob Kroese | last post by:
I've got a form with a datagrid that displays a list of items, along with several textboxes, comboboxes, etc., that display the details for the selected item. The columns in the datagrid and the...
2
by: Nate | last post by:
I have used the feedback on this issue to remedy my comboboxes showing the first item on the list when a new record is added to the binding context --- Me.BindingContext(dsOrders,...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
12
by: eetarnold | last post by:
Hi Gurus, As I've read in other posts the past couple of days, I've read many great posts and haven't figured out how I can solve this problem...I'm trying to make a form very user friendly for...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.