3314 on a combobox with autocomplete in access - ms-access

I have created a combo box ("product" field) to autofill other fields ("product code" and "boxes") in a subform. I use in "on change event" this code:
Option Compare Database
Option Explicit
Private Sub PRODUCTO_Change()
Me.CODIGO.Value = Me.PRODUCTO.Column(1)
Me.CAJAS.Value = Me.PRODUCTO.Column(2)
End Sub
But when I make a mistake typing the word and the autocomplete function mismatches, or when I try to correct with backspace, an error window pops up telling "Run-time error "3314": you must enter a value in the "productos pedidos.codigo" field where "codigo" is a primary key of one of my database tables.
I tried deleting the subform and creating it again, changing the field names, but the issue persists. I can just select the product searching the word whit the scrollbar in the list without autocomplete, but I have nearly 200 hundred diferent products and I need the autocomplete function.
Thanks in advance

Related

MS Access Combobox's value doesn't exist in table/query

I have some ComboBoxthat are configured in table/query mode, that means that they get the list of items from a table in the database of Access.
Normally, this ComboBox -called Editar_Codigo and Editar_Nombre- only use the items from the list, but sometimes I want to wrote new items that still doesn't exist in the table (because then I'll press the "add record to table" button).
But there I get the problem, Access spawn a PopUp saying that the values in both ComboBox doesn't exist in the table, and I can't close that PopUp until I delete the wrote value in both ComboBox.
I found that exist an expresion that is activated when a ComboBox get a value that doesn't exist.
Private Sub ComboBox_NotInList(NewData As String, Response As Integer)
End Sub
But even using that, this happened:
First, I wrote the "wrong" value.
Second, the ComboBox_NotInList (in my case Editar_Codigo_NotInList and Editar_Nombre_NotInList) is executed. (I check it open an MsgBox).
Finally, the Access PopUp is open.
I want to delete the third item of the above "chain event". How can I do that?
Edit:
The idea is to write the code of the product in the Editar_Codigo ComboBox, the name in Editar_Name and the price and stock in the next two TextBoxs. And finally, press the button called "Añadir", which will add the record to the table called "Lista de Stock".
But the problem is that I can't write "inexistent values" in the ComboBoxes (values that doesn't exist in the table). So I want to be able to "ignore" the PopUp, How can I make Access to not raise a PopUp?
set limit to list property of combo box under data tab to no .
ok. I think What you can do is . First of all make that combo to see only one column Alpha, beta ,Gamma. Now whenever user selects the Beta than set property of combo box i.e. and write code to fetch corresponding value from table.
Example. Suppose name of combobox is combo1.
colomnInvisibleValue = dlookup("colomnName","TableName","VisibleColomnName= '" & me.combo1.value & "' ")
Variable colomnInvisibleValue will contain value (2) according to your last comment.!

How do I get a Dlookup result to display within another textbox on an Access database?

I have created on a database a Dlookup function to change the email address of a manager whenever the managers area is selected. It works fine but now that the control source is the Dlookup it doesn't save the results any more in the personal table.
I read up on http://p2p.wrox.com/access-vba/77907-how-save-results-dlookup-function.html a method to have a separate hidden box which displays the results from the table, which works but my trouble is now connecting the Dlookup result to the other text box.
I obviously cant control source the Dlookup result so I've instead tried to make it an before update event using the following code;
Option Compare Database
Private Sub ASMail_AfterUpdate()
ASMEmail.Value = ASMail.Value
End Sub
However this has not taken effect at all. The textbox does not change whenever I adjust the Dlookup results, and I've tried the same code in the other Change event which didn't work either.
You don't need a separate hidden textbox.
Leave the textbox control source of the manager's email linked to the personal table field and simply update the textbox value to the DLookup value when the manager area is selected.
I don't know how the manager area is selected, but as a combobox example, it would be like this:
Private Sub Combo_AfterUpdate()
Me.ASMEmail.Value = Nz(DLookup("Value", "Domain", "Criteria"), vbNullString)
End Sub

Use a text box as a wildcard search on a field within a linked SQL Server Table within MS Access

I've managed to successfully build a combo-box that will allow a user to select a record from a list to get an ID from a table. With the table I'm currently working with running to around 60,000 records, it's not realistic to use this method to find the record.
What I want the user to be able to do is enter a name in a text box, and a combo box be populated with the relevant records from the table where one of the fields matches that. So if the user entered 'This' into the text box, the combo box would present records where the field had 'This', 'This and That' and 'this'. It would not present the record that only had 'That' in the field.
Lets say the Text box is called 'txtBox', the combo-box is called 'comBox' and the field in the linked SQL Server table 'LinkedTable' is called 'SearchField'
I would suggest you not use the combo box. Just have a text box in which the user can type in a few characters and hit enter key.
You THEN display a “list” of results that allows the user to select and click on any of the results to “edit” or “view” the given row of data.
In the following screen shot we working with a VERY small table of 500,000 rows. We looking for smith, so we just type in smi and hit enter. The results are displayed instant, and at that point the user can type in “first name” or just a few chars of first name and further drill down and filter.
The form looks like this:
The code in the after update event of the text box is simply:
Dim strSQL as String
strSQL = "select * from tblCustomers where LastName like '" & me.TextSearch & "*’"
me.RecordSource = strSQL
So very little code is required. You could I suppose fill in the results to a combo box, but then the user has to type into a box, then select something from a combo box and then somehow you bring up that record for editing. That’s like 3+ steps for the user.
Just use what Google or most accounting or darn near any computer software does:
A simple text box – you type in a few characters and when they hit enter the results are displayed for the user to pick.
Note in above the user can click on the “glasses” icon button to launch a form that displays the single record. The code behind that button is:
Docmd.Openform "frmEditDetails",,,"ID = " & ME!ID
I went down a different route to the suggested option in the other answer. This met my needs more accurately and might help someone with a similar issue.
First, I amended the query on the Combo box so that it used the value in the text box as a criteria for one of the fields.
In the Criteria for the 'SearchField' within 'LinkedTable' I entered:
Like "*" & [forms]![*FormName*]![txtBox] & "*"
This will restrict the results in comBox to those where the SearchField contains the value entered into txtBox. This doesn't update dynamically however and will only update after the first value entered into txtBox.
To get around this problem, I added the following to the 'On Get Focus' event for comBox
Private Sub comBox_GotFocus()
Dim ctlCombo As Control
' Return Control object pointing to a combo box.
Set ctlCombo = Forms!FormName!comBox
' Requery source of data for list box.
ctlCombo.Requery
End Sub
This will force the combo box to run the query again, using the current value in txtBox, each time it is 'clicked on'
As a result, I get the restricted list of values in the combo box that I need and allows the user to 'search' for a record that can then be used for creating a new record on a form.

Access SubForm recordsource revert to original

I have an Access form with two subforms, both in continuous mode. Since I cannot have a subform inside a continunous form, I had to do it that way (Datasheet is not an option either)
Either way, when I click on my first subform, I change the other subform record source using some rather simple code :
Public Sub MAJFiltre(intIdMembership As Integer)
IdMembershipFiltre = intIdMembership
Me.RecordSource = "SELECT * FROM T_PeriodeMembershipPartipant WHERE IdPeriodeMembreship=" & IdMembershipFiltre
Me.Requery
End Sub
This function is called from the first subform. I did this for another form and it was working fine. For this one, if I use a breakpoint, I can see the recordsource is changed, but nothing happen in the UI. However, if I put a breakpoint in a BeforeInsert event, I can clearly see the recordssource reverting to the original one (with no WHERE clause)
I also notice something unusual : If I save the form code while debugging, all of a sudden, it works. However, as soon as I close the form, it revert back to its "buggy" version.
Does anyway have an idea of what is going on and how I can correct /prevent it ?
Thanks
It sounds similar to a problem we suffer periodically, which relates to subforms linked to a parent form with link master/child ids: If you've (ie Access has done it for you) unintentionally saved a filter value as a property in one of the subforms, (filter by or in a record source), when your code reassigns the record source, this saved value prevents the new record source from being assigned correctly, and ms access then does what it thinks is best - in this case, reverting to the valid (prior) record source.
Check your subforms for unwanted saved values of data-tab properties.
Could the problem be that your field name is misspelled in your query criterion?
IdPeriodeMembreship
If the field in your T_PeriodeMembershipPartipant table is IdPeriodeMembERship instead of IdPeriodeMembREship your query would likely prompt you to enter the parameter value manually when it is run.
If that field does exist in your table but the value you're specifying in your criterion isn't found in that field, it will return no results and the second subform's recordsource will be set to an empty recordset.

MS Access form ID increment

I'm trying to set up a simple form in MS access to add a new record to a table full of contact information. Each time I add a new record using the form, I want an ID number field to increment by one against whatever the highest value in the ID field is. The code I have right now seems to be working:
Private Sub Contact_ID_Click()
Dim newContactID As Double
newContactID = DMax("[Contact_ID]", "Contacts") + 1
Contact_ID = newContactID
End Sub
The problem is that every time I start the database, open up the form in form view and click on the Contact_ID field to increment it, I get the following error message:
"The expression On Click you entered as the event property setting produced the following error: Object or class does not support the set of events."
I go to design view, open up the code, and then as soon as I switch back to Form view it's working again. I'd like it to work when the form is opened from scratch as others might be using this form and wouldn't know what to do. Any idea what's causing this?