Another combo box problem?

E

excyauseme

Hi guys. I've been reading these threads for days, and learning a lot
(I'm pretty new to this I'll apologize in advance).
I am trying to rehab an old mdb that has one main entry form.
The form has 4 tabs on the footer to go back to the Main Menu
switchboard,
Add a new Record, Undo changes, and Delete a Record.

Originally it has a list box with a Instruction # as the Key. It was
in a text format, 11 bytes, like 111.01-001. Well, the users wanted to
be able to search by splitting this Instruction # out into 2 fields,
Group (111.01) and Inst# (001). So I added those fields to a table.
The Group field will never change, so the users can't enter in their
own text. However the Inst# should increment if it is a new record (I
was wondering if I should have the NotinList after it's keyed, or if
once they click the arrow >* the Inst# is autonumbered, I'm not sure
how to do that...

So I tried to add a cascading combo box to the form - by Group, and by
Inst# (these are text, unbound). The Group field (cbo1) can have
multiple Inst#'s (cbo2). Then there are a bunch of fields that need to
be entered on that form after the combo box criteria are entered or
selected in cbo2.

I set cbo2 to LimittoList=True, and had a NotinList procedure added
(which I'll attach).
I need to have the ability for a user to add a new Inst# (combo box 2)
if they are Adding a new Record. Then I have to go back to the form
and continue entering the rest of the fields.

I'm getting a bunch of errors. Since the lookup is by Group and by
Inst#, I'm getting very lost in all this. Can anyone help a noob like
me? Am I overcomplicating things a lot?

Here it is , for any wonderful souls who can help me out:

1) My afterupdate for combo box #1, which doesn't allow the users a
choice.

function for combo box - Group Number
Private Sub cbo1_AfterUpdate()
On Error Resume Next

cbo2 = ""
cbo2.Requery

End Sub

2) AfterUpdate - after Inst# is chosen (cbo2)

Private Sub cbo2_AfterUpdate()
On Error GoTo Err_cbo2_AfterUpdate_Text
Dim rs As DAO.Recordset

'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If

'Search in the clone set.
Set rs = Me.RecordsetClone
rs.FindFirst _
"[GROUP] = '" & Me!cbo1 & "'" & _
" AND " & _
"[InstNbr] = '" & Me!cbo2 & "'"
If rs.NoMatch Then
MsgBox "Existing Group and Instruction # Not Found."
Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing

Exit_cbo2_AfterUpdate_Text:
Exit Sub

Err_cbo2_AfterUpdate_Text:
MsgBox Error$
Resume Exit_cbo2_AfterUpdate_Text

End Sub

3).

Private Sub cbo2_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cbo2_NotInList
Dim db As DAO.Database
Dim i As Integer
Dim strMsg As String
Set db = CurrentDb()

strMsg = "Do you want to add this instruction number'" & NewData & "'
to the table? "
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to continue and Add, or
No to re-type it."

i = MsgBox(strMsg, vbQuestion + vbYesNo)
If i = vbYes Then
NewData = cbo1 & "-" & NewData 'field INSTNO is the key, which
consists of cbo1 & cbo2.
db.Execute "INSERT INTO tblQAINST ([INSTNO]) VALUES (""" &
NewData & """)", dbFailOnError
Response = acDataErrAdded
Else
Me.Undo
Response = acDataErrContinue
End If

db.Close
Set db = Nothing

Exit_cbo2_NotInList:
Exit Sub

Err_cbo2_NotInList:
MsgBox Error$
Resume Exit_cbo2_NotInList

End Sub


I will post additional stuff as needed....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top