Okay, your Division combo is fine.
I would not use a bound combo for SeqNumber. That is dangerous. If have an
existing record and make a selection in the combo expecting it to navigate to
a different record, what will really happen is you will be changing the value
of the existing record, not moving to a new record. You should use a text
box for SeqNumber as the bound control. If you want to search by SeqNumber,
you can use your existing combo, but make it unbound. Here is how you use a
combo to search for a record:
Private Sub SeqNumber_AfterUpdate()
.Division.Enabled = True
.Division.Locked = False
With Me.RecorsetClone
.FindFirst "[SeqNumber] = " & Me.SeqNumber
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Now, there may also be an issue with your Division combo box. If a user
changes the value for an existing record, you may end up with two records
with the same number for the division the user changed to. For example.
Lets say you are on Division XXX (sorry don't remember the real names) and
SeqNumber 123. The user changes the value to YYY and there happens to
already be a SeqNumber 123 for YYY. Now you have two. So, here is my
suggestion.
Make the Division combo enabled only for new records. When you create a new
record and the user selects a division, create the SeqNumber, set its Enabled
property to No and its Locked property to yes. First we need a bit of code
in the form's Current event:
Private Sub Form_Current()
With Me
If .NewRecord Then
.Division.Enabled = True
.Division.Locked = False
Else
.Division.Enabled = False
.Division.Locked = True
End If
Now in the After Update event of the Division combo, we assign the next
number for the division:
Private Sub cboDivisionSelect_AfterUpdate()
With Me
.SeqNumber = Nz(DLookup("[SeqNumber]", "tblRPALog", "[Division] =
""" & .Division """"), 0) + 1
End Sub
Just a note, I will have to check back from time to time. I did not get a
notification this time, either. I just happened to be scanning posts and saw
it again.
--
Dave Hargis, Microsoft Access MVP
bbypookins said:
Yeah, you're out there! Thank you!
My Division field is actually a combo box bound to the query qryDivision
which is based on the table tblDivision.
I started a brand new form because it seemed there was something lurking in
the other one that was throwing me off. So, we can create whatever controls
you think will work for me. In my table I now have these fields: Division;
SeqNumber. In my form I have two controls with the same names. SeqNumber is
the combo box that has the code associated with it.
I was working on 2 fields with the understanding that we could later figure
out how to search by the combined fields.
Klatuu said:
Sorry bbypookins. Maybe I didn't click Notify me of replies.
I haven't given up, I just haven't received any notifications of your posts.
Okay, Me.Divison would be a text box control bound to the Division field in
your form's rowsource.
To bring me up to speed, did you decide to use two fields or are you still
wanting to use just one?
I can help better if you tell me that and the names of the controls on your
form that are involved and the field in your recordset they are bound to.
--
Dave Hargis, Microsoft Access MVP
bbypookins said:
Can someone please help me with this? I've been getting help from Klatuu but
I haven't gotten a response to my last few posts...I think he's given up on
me, which is understandable. For my original post, please see "form code to
create field." Here's my latest question.
I've got the current event working! Progress! But, I still can't get the
combo box to work.
Below is the code I have. I'm getting a "Compile error: Method or data
member not found" and it is highlighting ".Division =" of the first
Me.Division line.
Private Sub cboDivisionSelect_AfterUpdate()
Me.Division = Me.cboDivisionSelect
Me.SeqNumber = Nz(DLookup("[SeqNumber]", "tblRPALog", "[Division] = """
& Me.cboDivisionSelect & """"), 0) + 1
End Sub