I have a form with a number of look-up combo boxes and I was using the following code the open a form that enters the data into the field that the look-up is referencing by double clicking on the combo box. Additionally, if you typed in an entry that wasn’t there you received an error message.
I used this code in a database I built years ago (the one I am working on now is my second db) and I did so using look-ups in the table (I now know this is bad) and I also used an autonumber PK in every table. I prefer to use this code than have a number of buttons on the form to open the other forms, as it clutters and complicated the form.
I have recently removed the look-ups from the table and placed them in the form. Additionally, I deleted the autonumber PKs from the tables from which the look-ups reference. Additionally, I have implemented MajP’s code to turn my combo boxes to Find As You Type combo boxes (see thread702-1584791).
The code above refers to the list of Manufacturers, the table for which is as follows
Manufacturer
Man dbText PrimaryKey Indexed
When the code was working, the table was like this:
Manufacturer
ManID dbLong PrimaryKey Indexed
Man dbText
The form that contains the look-ups controls the following table:
Tool_Log
ToolID dbLong PrimaryKey Indexed
ManID dbText Indexed
Serial dbText Indexed
TypeID dbText Indexed
Size dbText Indexed
Description dbText
Set dbText Indexed
Year dbText Indexed
RRP dbCurrency
PurID dbText Indexed
Date dbDate
LocID dbText Indexed
ImagePath dbText
The look-up stored the selected data into a field called ManID in the main table that I use.
I knew that the initial issue would be that the autonumber PK in the Maufacturer table (ManID) no longer existed, yet the name ManID was present in the Tool_Log form/table.
I mad a copy of the database and then I tried replacing every instance of ManID with Man (in the code, the forms and tables). However, this didn’t work.
Any assistance is greatly appreciated.
Code:
Private Sub ManID_DblClick(Cancel As Integer)
On Error GoTo Err_ManID_DblClick
Dim lngManID As Long
If IsNull(Me![ManID]) Then
Me![ManID].Text = ""
Else
lngManID = Me![ManID]
Me![ManID] = Null
End If
DoCmd.OpenForm "Manufacturer", , , , , acDialog, "GotoNew"
Me![ManID].Requery
If lngManID <> 0 Then Me![ManID] = lngManID
Exit_ManID_DblClick:
Exit Sub
Err_ManID_DblClick:
MsgBox Err.Description
Resume Exit_ManID_DblClick
End Sub
Private Sub ManID_NotInList(NewData As String, Response As Integer)
MsgBox "Double-click this field to add an entry to the list."
Response = acDataErrContinue
End Sub
I used this code in a database I built years ago (the one I am working on now is my second db) and I did so using look-ups in the table (I now know this is bad) and I also used an autonumber PK in every table. I prefer to use this code than have a number of buttons on the form to open the other forms, as it clutters and complicated the form.
I have recently removed the look-ups from the table and placed them in the form. Additionally, I deleted the autonumber PKs from the tables from which the look-ups reference. Additionally, I have implemented MajP’s code to turn my combo boxes to Find As You Type combo boxes (see thread702-1584791).
The code above refers to the list of Manufacturers, the table for which is as follows
Manufacturer
Man dbText PrimaryKey Indexed
When the code was working, the table was like this:
Manufacturer
ManID dbLong PrimaryKey Indexed
Man dbText
The form that contains the look-ups controls the following table:
Tool_Log
ToolID dbLong PrimaryKey Indexed
ManID dbText Indexed
Serial dbText Indexed
TypeID dbText Indexed
Size dbText Indexed
Description dbText
Set dbText Indexed
Year dbText Indexed
RRP dbCurrency
PurID dbText Indexed
Date dbDate
LocID dbText Indexed
ImagePath dbText
The look-up stored the selected data into a field called ManID in the main table that I use.
I knew that the initial issue would be that the autonumber PK in the Maufacturer table (ManID) no longer existed, yet the name ManID was present in the Tool_Log form/table.
I mad a copy of the database and then I tried replacing every instance of ManID with Man (in the code, the forms and tables). However, this didn’t work.
Any assistance is greatly appreciated.