So the problem is that i am having two combo boxes in ms access subform. First is ProductID and Second is BatchID. I want to filter the BatchID for the ProductID I select.
I have placed the following code to filter the BatchID
Private Sub SetReSrc()
Me.cbo_BatchID.RowSource = "qry_BatchID"
End Sub
Private Sub cbo_ProductID_AfterUpdate()
SetReSrc
End Sub
For the first record it works fine. But as I enter the Product in the next record it removes the previous BatchIDs. It makes sense that it is updating the BatchID to the current selected ProductID but i want to keep the earlier ones and update only the last one.
How can I can do this.
Thanks in advance.
"For the first record it works fine. But as I enter the Product in the next record it removes the previous BatchIDs. It makes sense that it is updating the BatchID to the current selected ProductID but i want to keep the earlier ones and update only the last one."
If the batchids is a tied to a field as the control source, then MS Access is already doing what you want, by keeping/storing all previous values of the batchid to each record.
Ensure you are not using an unbound form control for the batchid.
Related
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.!
I am trying to write a value to a record as soon as it is pulled into the form in Access. I put the code into the Form_current event code, thinking this would work, but I am getting an unexpected result. It is writing to the previous record. So for example if I go from record A to record B, it will write the values to the fields in record A. Oddly, if I have a message box display the value of the field it will display the value from record B, though. It is very simple code, but here is what I have. I tried the RefreshRecord and DoEvents, because i thought they might help, but they did not.
Private Sub Form_Current()
Dim username As String
username = Right(Environ("USERPROFILE"), Len(Environ("USERPROFILE")) - InStrRev(Environ("USERPROFILE"), "\")) 'Removes path and keeps the Novell ID
DoCmd.RefreshRecord
DoEvents
Me.Record_lock = vbTrue
Me.Locked_by = username
End Sub
Any help on this would be appreciated. I have worked with VBA before in Excel, but never really in Access
Form_Current can fire repeatedly while the form is open ... not just once when the form is first opened.
From the Form.Current Event help topic ...
Occurs when the focus moves to a record, making it the current record,
or when the form is refreshed or requeried.
So with your code, it's not surprising that you have updated Record_lock and Locked_by values for record A after you navigate away from record A to record B.
At that point, record B has become the "current record", so it should have those updated values, too. You confirmed that point with MsgBox. However, the changes to that record may not have yet been saved, which means you would not see them in the source table yet.
If the remaining issue is that you're not seeing the updated record B values displayed in the form, add Me.Refresh on a separate line before End Sub.
I would like to comment first, but I am a new user. Have you tried refreshing the record, before modifying the field?
I'm wanting to get a record count of my subform each time it is filtered in some way. The text box containing the record count value will be held on the main form.
The record count method I'm familiar with is:
Trim([FORM/SUBFORM ADDRESS].RecordsetClone.RecordCount)
This works fine where the subform is being filtered by changes to Record Source's SQL via VBA.
More recently though I've added the ability for the user to also filter on the subform columns using command buttons running acCmdFilterMenu, i.e. these type of menus:
I've put the record count method in a module so it could be called globally between form and subform events:
Public Sub InboxCount()
Forms!Home.txtInboxCount = Trim(Forms!Home!tblJob_Search_sub.Form.RecordsetClone.RecordCount)
End Sub
I'm then calling the record count in the subform's OnApplyFilter event:
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
MsgBox "Filter Applied"
InboxCount
End Sub
The test message "Filter Applied" fires so it is running the code in that event, it just seems that the record count method I'm using doesn't work when the subform is filtered using acCmdFilterMenu... it does work when I filter the subform using commands that change the Record Source's SQL though.
How might I get the subform's record count when the subform is filtered using acCmdFilterMenu?
Create a textbox (you can hidde it with Visible=False) in the footer section of the subform and set it's sourceObject to =Count(*)
Let's name it txtRecordCount.
In your parent form, create another textbox that references the previous textbox. Set the SourceObject to =[NameOfSubformControl].Form![txtRecordCount]
I am sure I am approaching this incorrectly since there has to be a design issue with the database but I am willing to try anything right now.
On a form I have a main subform containing a drop down of different types of lands and two buttons (Prev and Next). This subform data source is a table called Section22_PMLU
Nested in this subform is another subform linked to the parent subform using the PMLU_Code. This data is being updated to table Section22_Data.
When a user clicks the drop down on the parent subform and makes a land selection and then chooses details (characteristics of land) in the child subform this data is correctly displayed in the Data table. Even if the user clicks the drop down again (w/out creating a new record) and adds child records this is reflected in the data table.
The issue is with the PMLU table. If I initally make a selection and add data from nested subform this record is recorded/displayed in the PMLU table. If I click in the drop down field and click "Add New Record" or press Ctrl+ and then choose a new item from drop down - it is recorded/displayed correctly in the table. HOWEVER if I make a selection without creating a new record first this item copies over the one added previously. WHen I attempt to go back (prev button) to see the record it is not displayed. However it is still in the data table.
In order to correct this issue I have to go directly into the PMLU table and add the missing PMLU codes that match the PMLU codes found in the data table.
If I run the following query I get those missing PMLU's. How can I use the results to populate the PMLU table with the missing codes
SELECT Section22_2_Data.PMLU_Code, Section22_2_Data.PMLUType
FROM Section22_2_Data LEFT JOIN Section22_2_PMLU ON Section22_2_Data.[PMLU_Code] = Section22_2_PMLU.[PMLU_Code]
WHERE (((Section22_2_PMLU.PMLU_Code) Is Null))
I used the following code to refresh the table which fixed the issue
Private Sub btnRefresh_Click()
Dim strSQL As String
strSQL = "INSERT INTO Section22_2_PMLU ( PMLU_Code )
SELECT DISTINCT Section22_2_Data.PMLU_Code
FROM Section22_2_Data LEFT JOIN Section22_2_PMLU ON Section22_2_Data.[PMLU_Code] = Section22_2_PMLU.[PMLU_Code]
WHERE (((Section22_2_PMLU.PMLU_Code) Is Null));"
CurrentDb().Execute strSQL, dbFailOnError
' Next 3 only to ensure the append is commited to the table '
' before requerying '
DoEvents
DBEngine.Idle dbRefreshCache
DoEvents
Me.Requery
End Sub
I use a subform to show the result of a query, but at the end of record there is a *(New) for adding new records. I don't want the user to be able to add new records through this subform. How can I get rid of this?
With the subform in Design View, open its property sheet. Then select the Data tab on the property sheet, find the property named "Allow Additions" and set it to No.
The "Allow Additions" property will not display if you open the design view of the parent form and click on the subform. The subform must be opened in Design View independent of the parent form.
Had exactly the same problem.
My DB is to keep track of basketball box scores. Every new main form created a new blank subform to enter the quarter scores into. The problem was as I Entered through the fields once I hit enter on the last quarter score value a new record was created for the table that Quarter Scores was based on.
I could not use Allow Additions = no. If I did not allow additions there was no quarter score input created when a new main form (for a new game) was created.
I used the code below for a key down event of the Enter key to set the focus on another subform before a new quarter score record was created.The commented lines were to help trouble shoot when creating the code. Key code 13 is the Enter key.
Hope this helps someone, took a while to get this right.
Den
Private Sub HOT2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> 13 Then Exit Sub
'MsgBox "Enter Pressed"
KeyCode = 0
'MsgBox "KeyCode=0"
Forms!FRM_BoxScores.Scrimmage.SetFocus
Forms!FRM_BoxScores!subform_qryReturnVisitingPlayers_BosScores.Form!subform_tblPlayerPoints_BoxScores.Form!PlayerPoints.SetFocus
End Sub
Change Record-set Type to Screenshot in Data Form Properties > Data Tab. Please note user cannot change any Data in form you once you change this
in your subform design grid, open the properties.
Where is says recordset type, set it to snapshot. That will remove that line.
The recordset will NOT be updateable at that time. So if you want to edit records, you have to change it back