I have a form that I have placed a toggle button so the user may clear the data they've previously from three combo boxes. I've created an SQL to delete the data in the table the form is bound to, but the combo boxes are still retaining the data despite the table being clear of any data. How can I reset the combo boxes? Even when I have the form open and close, the old data is still in the combo box. I would like to reset those combos.
Private Sub Reset_Company_Marketer_Product_Click()
Dim DltPrvCompMarkProd_TableSQL As String
DltPrvCompMarkProd_TableSQL = "DELETE User_SubProducts.* FROM User_SubProducts;"
DoCmd.SetWarnings False
DoCmd.RunSQL DltPrvCompMarkProd_TableSQL
DoCmd.SetWarnings True
Private Sub Reset_Company_Marketer_Product_Click()
Dim DltPrvCompMarkProd_TableSQL As String
DltPrvCompMarkProd_TableSQL = "DELETE User_SubProducts.* FROM User_SubProducts;"
Me!Company_Select_Combo = Null
Me!Marketer_Select_Combo = Null
Me!Product_Select_Combo = Null
Company_Select_Combo.Enabled = True
Marketer_Select_Combo.Visible = False
Product_Select_Combo.Visible = False
DoCmd.SetWarnings False
DoCmd.RunSQL DltPrvCompMarkProd_TableSQL
DoCmd.SetWarnings True
Related
Problem: I have records that act like information snapshots, and I need to be able to change a yes/no field from False to True on the current existing record when I save a new record.
For arguments sake, records X and Y are the same subject, just at different point in time (same document, different revisions). I need to save a new record, record Z, which is the same subject with today's updates. When I save record Z, I want record Y to have a checkbox modified from False to True to show it is obsolete.
When saving a new record, I do have an unbound text box that displays the existing record number (named txtID). Is there a way I can piggyback a reference to that box in order to change a check box control (named chkObs) on that record?
My current coding to save a record is as follows:
Private Sub cmdSave_Click()
DoCmd.OpenTable "tblTasks", acViewNormal
DoCmd.Requery
Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("Tasks")
rs.AddNew
rs("Namefield").Value = Me.NameD.Value
rs("Reqt").Value = Me.ReqT.Value
rs("Plant").Value = Me.Plant.Value
rs("Requestor").Value = Me.Requestor2.Value + " " + Me.Requestor.Value
rs("TaskDue").Value = Me.TDD.Value
rs("AssignedERDM").Value = Me.AE.Value
rs("Package").Value = Me.SUBN.Value
rs("Comments").Value = Me.COM.Value
rs("RequestRec").Value = Me.DRR.Value
rs("Hold").Value = Me.H.Value
rs("QuantityT").Value = Me.QT.Value
rs("QuantityC").Value = Me.QC.Value
rs("QuantityO").Value = Me.QR.Value
rs("ERDMLogged").Value = Me.ELT.Value
rs("Closed").Value = Me.Cl.Value
rs("Hyperlink").Value = Me.hy.Value
rs("DateMod").Value = Me.lm.Value
rs("StatusAW").Value = Me.SSO.Value
rs("CompleteDate").Value = Me.CD.Value
rs.Update
DoCmd.Close acTable, "tblTasks", acSaveYes
DoCmd.Requery
End Sub
In an access form, I have an unbound text box when contains a formula. The formula returns "Yes" or "No" based on whether the form has been completed (it ensure that all required boxes are filled in).
On the same form, I have a command button which I want to use to filter out completed forms. Basically, it is a button that save "Save Record" and when clicked, the form - if completed - should disappear (i.e. be filtered out).
Below is what I put in, but I don't know VBA.
Private Sub bttn_Save_Click()
Me.Filter = Me.MainFormComplete = Yes
Me.FilterOn = True
End Sub
How do I get check to see if my field (MainFormComplete) is equal to "Yes"?
Not quite sure what you are trying to do, but it could be:
Private Sub bttn_Save_Click()
Me.Filter = "MainFormComplete = 'Yes'"
Me.FilterOn = True
End Sub
or:
Private Sub bttn_Save_Click()
Me.Filter = "MainFormComplete <> 'Yes'"
Me.FilterOn = True
End Sub
or
if Me.MainFormComplete = Yes then
....
end if
the textbox might not be readable if text was simply entered and not saved. read the text:
if Me.MainFormComplete.Text = Yes then 'or "Yes" or True
....
end if
I have a datasheet subform with a combobox name Loan_ID_cbo. Whenever I update the filter via the combobox, the subform is updating the Loan ID (primary key) with the selected Laon ID from the subform, thereby changing the data on the table.
I would like to only filter this data and not allow the filter to edit the data on the table. How can I prevent this from happening?
Here is my VBA code for the After_Update event:
Private Sub Loan_ID_cbo_AfterUpdate()
Application.Echo False
Me.Filter = "MyKey = '" & Loan_ID_cbo & "'"
Me.FilterOn = True
If Loan_ID_cbo = "" Then
Me.Filter = ""
Me.FilterOn = False
End If
Application.Echo True
End Sub
If I understand correctly, your combobox is in the subform datasheet. Thus the combobox appears on each row.
It does happen probably because your combobox is bound to the field Mykey. So changing the combobox do change the value of Mykey.
You should not make a filtering combobox out of the myKey field in the subform, you should make an unbound combobox in the parent form :
In the subform, delete this combobox, and add a new textbox and bind it to Mykey.
On your mainform, create a new combobox and use this one to filter your subform. So the code would be something like :
Private Sub Loan_ID_cbo_AfterUpdate()
Application.Echo False
Me.subformname.Form.Filter = "MyKey = '" & Loan_ID_cbo & "'"
Me.subformname.Form.FilterOn = True
If Loan_ID_cbo = "" Then
Me.subformname.Form.Filter = ""
Me.subformname.Form.FilterOn = False
End If
Application.Echo True
End Sub
I recently migrated an Access database (that someone more knowledgeable than I designed) to MySQL, and linked the tables back into Access to use as a front end. Almost everything looks great. There is just one form and chunk of VBA code that doesn't seem to work. There is a form that should show drop down menus and controls, but is blank in form view. The form in design view and form view The VBA code that goes with the form is
Option Compare Database
Private Sub cmdPreviewPlate_Click()
'show user the new plate that is to be added to tblPCRsamples
On Error GoTo Err_cmdPreviewPlate_Click
'check whether boxes are blank
Dim bolBlank As Boolean
bolBlank = False
If IsNull(Me.Controls!cboChooseTemplatePlate) Then bolBlank = True
If IsNull(Me.Controls!cboChooseLocus) Then bolBlank = True
If IsNull(Me.Controls!txtEnterDate) Then bolBlank = True
If bolBlank = False Then
'enable the Add button
Me.Controls!cmdAddPlate.Enabled = True
'generate the unique PCRplate from the template plate number and locus
' using the global variable GstrPCRPlateName so that the queries can add the plate name to both tables
GstrPCRPlateName = Me.Controls!cboChooseTemplatePlate.Value & "_" & Me.Controls!cboChooseLocus
'check: does this PCRplate already exist in tblPCRplates?
Dim dbs As Database
Dim rst As Recordset
Dim bolDone As Boolean
Dim bolNameExists As Boolean
bolDone = False
bolNameExists = False
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblPCRplates", dbOpenDynaset)
rst.MoveFirst
Do Until bolDone = True
'does the new plate name automatically generated here = the value of PCRplate in the current record?
If GstrPCRPlateName = rst![PCRPlate] Then
bolNameExists = True
bolDone = True
End If
rst.MoveNext
If rst.EOF Then bolDone = True
Loop
'if the name already exists, make a new name by appending _ and the date
If bolNameExists = True Then
GstrPCRPlateName = GstrPCRPlateName & "_" & Me.Controls!txtEnterDate
End If
'set the value for the Locus
GstrGetLocus = Me.Controls!cboChooseLocus
'open the select query to show user what they're going to add to the PCR plates & samples tables
Dim stDocName As String
stDocName = "qryNewPCR_1SelectTemplatePlate"
DoCmd.OpenQuery stDocName, acNormal, acReadOnly
Else
'if user left fields blank (except page number, that can be blank), show an error message
MsgBox "Choose/enter values for all the boxes"
End If
Exit_cmdPreviewPlate_Click:
Exit Sub
Err_cmdPreviewPlate_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewPlate_Click
End Sub
Private Sub cmdAddPlate_Click()
'add this new plate to tblPCRplates and tblPCRsamples
On Error GoTo Err_cmdAddPlate_Click
'add the new plate to tblPCRplates
Dim stDocName As String
stDocName = "qryNewPCR_2AppendPlate"
DoCmd.OpenQuery stDocName, acNormal, acEdit
'run the query to append the samples to tblPCRsamples
stDocName = "qryNewPCR_3AppendSamples"
DoCmd.OpenQuery stDocName, acNormal, acEdit
'open frmPCRSamples to show the new plate has been added
stDocName = "frmPCRSamples"
DoCmd.OpenForm stDocName, acFormDS
Exit_cmdAddPlate_Click:
Exit Sub
Err_cmdAddPlate_Click:
MsgBox Err.Description
Resume Exit_cmdAddPlate_Click
End Sub
So my question is, should the linked tables be causing errors? Is there something I can amend to say that they are linked? Or am I barking up the wrong tree?
Thanks for your help. I know nothing of VBA (I mean, I can follow along) and have been tasked to destroy, I mean...admin...this database. This is what happens when you give biologists computers ;-) Even just some good resources would help a great deal.
The happens when your RecordSource of the form returns zero records and the form or record source does not allow adding new records.
Check the record source (table, query, or SQL string) and run it manually to see if it returns records.
I have a form ("Patient Complications") where users input data to a form using 2 cascading combo boxes ("catcombo" and "speccombo"). The combo boxes pull their values from a table ("Complications"). The table has a field for complication category (for example, infection, bleeding, mechanical). A second field lists specific complications (for example, if the complication category is "bleeding", the specific complication could be "GI" or "other"). The input from the combo boxes are concatenated and put into a text field on the form ("Complication"). That part works fine.
My form has several command buttons, including "edit" and "save" command buttons. Since I don't want users interacting with the "complication" field on the form, I have the field become not visible when the "edit" button is clicked. Instead, the 2 combo boxes become visible and allow users to input data. When "save" is selected, the reverse occurs. The two combo boxes become not visible, and the complication field becomes visible and locked.
Unfortunately, when "edit" is selected, the combo boxes are visible but show up blank (nothing is selected or displayed). I am trying to have the boxes display the inputs that were given to the text field. For example, if the text field displays "Bleeding, Other", I want the catcombo box to display "Bleeding" and the speccombo box display "Other". I have been unable to find anything to this effect. If anyone has any ideas it would be greatly appreciated.
The relevant code is included below. Please let me know if I can provide further clarification.
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
End Sub
Private Sub speccombo_OnCurrent()
Dim strsql As String
strsql = "SELECT [Complications]![Specific Complication] FROM tblComplications" & _
"WHERE [Complication Category]=Forms![Patient Complications]![catcombo].value"
End Sub
Private Sub speccombo_AfterUpdate()
Forms![Patient Complications]![Complication] = Me.catcombo.Value & ", " & Me.speccombo.Value
End Sub
Private Sub save_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = True
Complication.Visible = True
Complication.Locked = True
comments.Locked = True
catcombo.Visible = False
speccombo.Visible = False
Me.edit.Visible = True
Me.edit.SetFocus
Me.help.Visible = False
Me.save.Visible = False
Me.first.Visible = True
Me.next.Visible = True
Me.previous.Visible = True
Me.last.Visible = True
Me.addnew.Visible = True
Me.close.Visible = True
Me.cancel.Visible = False
End Sub
Private Sub edit_Click()
Me.recordcount.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.recordcount
Me.Patient_Initials.Visible = False
Date_of_Complication.Locked = False
Complication.Visible = False
comments.Locked = False
catcombo.Visible = True
catcombo.Locked = False
catcombo.Enabled = True
speccombo.Visible = True
speccombo.Locked = False
speccombo.Enabled = True
Me.cancel.Visible = True
Me.cancel.SetFocus
Me.edit.Visible = False
Me.help.Visible = True
Me.save.Visible = True
Me.first.Visible = False
Me.next.Visible = False
Me.previous.Visible = False
Me.last.Visible = False
Me.addnew.Visible = False
Me.close.Visible = False
End Sub
I figured it out. I added a field to the "Complications" table called "Input". This field contains the concatenated values that were put into the patient record (in the example above, the input field would be "Bleeding, Other"). The values in the Input field are the exact values that would be recorded in the "Complication" field on the Patient Complications form. I added the vba code below to the "Edit" command button code.
If Not IsNull(Forms![Patient Complications]![Complication]) Then
Dim comptext As String
Dim spectext As String
comptext = DLookup("[Complication Category]", "Complications", "Input = Forms![Patient Complications]![Complication]")
catcombo.Value = comptext
spectext = DLookup("[Specific Complication]", "Complications", "Input=Forms![Patient Complications]![Complication]")
speccombo.Value = spectext
End If
That solved my initial problem, but I then had an issue with the speccombo box displaying the last value it was given. For example, if speccombo.value="GI" when I click "edit", it would continue to display "GI" until another selection was made. This isn't a huge deal, just inconvenient. I wanted to make the speccombo box essentially zero out if catcombo was changed. I added the code below to fix that problem.
Private Sub catcombo_AfterUpdate()
Me.speccombo.Requery
Me.speccombo.Value = Null
End Sub
Please let me know if I need to provide clarification for anything.