Modules & VBA :: Look Up A Value In Table That Enable Or Disable Subform In Main Form
May 20, 2015
I have written code to look up a value in a table that then enables or disables a subform in my main form. The code works, but I know it is now as efficient as it can be. The main problem is that I have multiple values that determine if the subform should be enabled or disabled. I would like to use an IN statement but I'm pretty sure this doesn't work for Dlookup. Below is an example of the code I currently have:
Code:
Sub enablecontrols(setting As Boolean)
Inv_subform.Enabled = setting
End Sub
Private Sub Form_Current()
[Code] ....
Like I said, this works fine, but I am concerned if I need to add more items to look up and the stability of the code in general.
I did a search in the form forum and couldn't find anything close that had a response.
I have a parent form and a sub form.
I have the parent set up to make the enable property false for the command buttons that aren't appropriate when you first open the form: Like Save and Undo.
I want to do the same for the child form, which has different data linked to the parent form.
The parent form always grays out the inappropriate boxes.
The subform will gray them out only if I open it as a stand-alone form. When I put the code in the Open, or Load or Gotfocus events I get an error message that it cannot locate the subform.
Hi every body . I got a a form and sub form. I want to disable sub form untill the user finishes selecting values from combo box drop downboxes. I be happy if some one show me how to do this.
Need some help here! I have a table where different types of records are recorded. Let say for argument's sake my tblMain looks like this:
RecID (autonumber) EntryType (Combo box linked to my tblEntryType) Field1 (text) Field2 (text)
I then have tblEntryType which lists the different types of entries to be made and which fields are required on my form and what the lables should be. The structure looks more or less like this:
On my form, my record source is tblMain. When my user makes a selection in the combobox EntryType, there is a lot of code behind the AfterUpdate function like this:
I find this setup a bit labour intensive, especially as my form has quite a few fields! Is there a way that I can "look up" which fields are required from the table and enable/disable and label based on my tblEntryTypes without me having to creating so much code/use the "column" function.
Let me know if I am not making myself clear and I will be glad to try explain so more!
Need some help here! I have a table where different types of records are recorded. Let say for argument's sake my tblMain looks like this:
RecID (autonumber) EntryType (Combo box linked to my tblEntryType) Field1 (text) Field2 (text)
I then have tblEntryType which lists the different types of entries to be made and which fields are required on my form and what the lables should be. The structure looks more or less like this:
On my form, my record source is tblMain. When my user makes a selection in the combobox EntryType, there is a lot of code behind the AfterUpdate function like this:
I find this setup a bit labour intensive, especially as my form has quite a few fields! Is there a way that I can "look up" which fields are required from the table and enable/disable and label based on my tblEntryTypes without me having to creating so much code/use the "column" function.
Let me know if I am not making myself clear and I will be glad to try explain so more!
Hello. I have a form with a million little buttons on it (don't get me started, I didn't design it! - heh)...
Depending upon which user is running the mdb, I would like all but 16 (of the 80 or so) objects/controls disabled/enabled. I would like to autodisable all the controls, then enable the subset (or all of them) depending who the current user is.
SO in short, other than individually disabling/enabling the many items, is there a magic command for vba, similar to enable *.* for controls [silly e.g., but I hope you get my point...]
I am asked to create a checklist for a number of tasks to be executed in a particular shift. However in some tasks can be skipped. There are three shifts per day.
To accomplish this i have created a continious form with a number of checkboxes per task which represent the days of the week. The tasks itself are stored in a seperate table with a checkbox per shift (task settings). If the tasks must be performed in a particular shift, the checkbox is activated (= true).
Goal here is, if a task doesn't have to be executed in a shift the task should not be visible on the continious form. The recordsource of the continuous form is a query, which contains a join between the table with the task settings and the table with the tasks performed.
I have placed some code to perform the task in the form's current event
In the continuous form current event I have placed for every checkbox the following code:
Private Sub Form_Current() If Me. PerformTaskShift.Value = True Then Me.MaandagOchtend.Enabled = False End If End Sub
However when i execute the code and load the form, not only the checkbox in the row mentioned are set invisible, all the rows are. Is there any way to set only the checkboxes on the rows mentioned invisible, in stead of all rows?
Basically I want to put a code in the "on load" event of a form that enables or disables navigation buttons based on a value in a table (the table has 1 record and 1 column).
So if the value is "A", I want to hide navigation buttons on load; if it is "B", I want to show navigation buttons on load.
I know I can set this property in each form, but I have a number of forms that I want to configure at the same time.
My problem is that I don't know how to reference the value in the table.
I need to hide my subform on load or open of the main form but am experiencing some weird results. I have tried putting Me.SubForm.Form.Visible = False in both the on open and the on load of the main form and it works only if the tables on which the subform have records in them. If the tables for the subforms are empty I get an error 2467 telling me that "The expression you entered refers to an object that is closed or doesn't exist." I find this strange because from all I can find the subform loads first.
How can I hide the subform when the main form opens no matter what records exist or don't?
I have a form - purchase, and a subform purchase detail they are linked with a field "puid"..I need the dmax to give me the maximum auto number field "pdid" on the subform in a textbox on the mainform.
I'm using form with subform. Main form header contain a combobox. I need to check the combobox is null or not before update a subform filed. If combobox is null then its back to Main form combobox from subform. The code below that I'm trying to:
Code: Private Sub AssignTo_BeforeUpdate(Cancel As Integer) If IsNull(Forms!frmDepartmentReview!cboDepartment) Then MsgBox "You must select Department first", vbInformation Forms![frmDepartmentReview]![cboDepartment].SetFocus End If End Sub
Then I'm getting 2110 run time error
Access can't move the focus to the control cboDepartment.
I have an unbound mainform and an unbound subform(datasheet). The source of the subform is a query which is dynamic(I have many queries with diffrent columns). the subform source is change using a combo box selection. I have text boxes in my mainform..how do I get the data from subform to the text boxes of the mainform?
Here is my problem: When a certain yes/no box is true (checked) other fields on the form are not enabled. That works just find when I am on the record that I click the yes/no field. When I go to another record and then go back to the previous record the fields that should be disabled due to a certain yes/no box being true are now enabled and not disabled. Below is my code. Can anyone tell me what I am doing wrong?
On searching the forum, I found the following post for enabling/disabling BypassKey. I did as instructed but on clicking the label, it gives 'syntax error with 'On Error Goto' in red color and highlighted.
Hello af1112 welcome to the Forum...
I use this code that ghudson supplied at the beginning of this post.
First of all create a copy of your db (Just incase.. )
Now......
Create a label on a form somewhere and make it invisible to other users (I have mine hidden in my main Switchboard)
The idea is that by clicking on the label you can activate/de activate the code without anyone else knowing about what you are doing..
Name the label "bDisableBypassKey" & hide it somewhere in the corner of your screen or something.
Copy & Paste the code inbetween the bold text to the onclick event of the label you have just created
Private Sub bDisableBypassKey_Click()
On Error GoTo Err_bDisableBypassKey_Click 'This ensures the user is the programmer needing to disable the Bypass Key Dim strInput As String Dim strMsg As String Beep strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & "Please key the programmer's password to enable the Bypass Key." strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password") If strInput = "MY PASSWORD" Then 'Change password to your own ChangeProperty "AllowBypassKey", DB_BOOLEAN, True
Beep MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & "The Shift key will allow the users to bypass the startup options the next time the database is opened.", vbInformation, "Set Startup Properties" Else Beep ChangeProperty "AllowBypassKey", DB_BOOLEAN, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & "The Bypass Key was disabled." & vbCrLf & vbLf & "The Shift key will NOT allow the users to bypass the startup options the next time the database is opened.", vbCritical, "Invalid Password" Exit Sub End If Exit_bDisableBypassKey_Click: Exit Sub Err_bDisableBypassKey_Click: MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description Resume Exit_bDisableBypassKey_Click
End Sub
Now paste this code in the Double click event of the same label
Private Sub bDisableBypassKey_DblClick(Cancel As Integer) Private Sub Disable_Click() Option Compare Database
Option Explicit
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant Const conPropNotFoundError = 3270
Set dbs = CurrentDb On Error GoTo Change_Err dbs.Properties(strPropName) = varPropValue ChangeProperty = True
Change_Bye: Exit Function
Change_Err: If Err = conPropNotFoundError Then ' Property not found. Set prp = dbs.CreateProperty(strPropName, _ varPropType, varPropValue) dbs.Properties.Append prp Resume Next Else ' Unknown error. ChangeProperty = False Resume Change_Bye End If
End Function
To Test click on your label to activate the password prompt and type in the wrong password (that will now disable the bypass key) and you will not be able to open the db by holding down the Shift button
to disable enter the correct password and you will be able to use the Shift button
Hi there I am new to Access and I am currently modifying an existing DB. Currently this DB has a main table which holds a bunch of Patient info such as:
Name Age AssignedStaff Condition etc....
The assigned staff field is populated from another table (Staff), which holds all the staff members working at the institution. However a couple of these individuals have left and they no longer want their name to show up on the form when inserting a new record. However we do want there name to still be in the DB for historical reporting purposes......My intital thought was to create another field in the Staff table that would hold either a "Active" or "Inactive" entry. Then just have a simple If statement to see if the staff member is active or inactive. Does anyone see any problems with this solution or propose a more efficient method.
I am creating a data entry form with combo boxes related to two different tables: TblEducationID EducationID - Auto# PK Education - Text TblMediaFill MediaFillID - auto# PK Incubation Time- text Incubation Temp - text
In my form, I have a combo box that the user selects the Education Type (Media Fill Test; Aseptic Technique Observation, Watch Video, etc....)
I want the incubation time and temp text boxes to be disabled unless Media Fill Test (ID#4) is selected on the first combo box. (I get a Procedure Declaration does not match error.)
Private Sub EducationID_AfterUpdate() If EducationID = 4 Then IncubationTime.Enabled = True IncubationTemp.Enabled = True Else IncubationTime.Enabled = False IncubationTemp.Enabled = False End If
Private Sub A300_Completed_AfterUpdate() If A300_Completed = True Then A300_Date.Enabled = False User1.Enabled = False Else A300_Date.Enabled = True User1.Enabled = True End If End Sub
for some reason when creating a new record the above disabled/enabled fields retain the same property of the last records check? The form in a single (not a continuous)
I have a modal form which has a single record which is then linked to a sub-form on the same modal form. This all works fine and shows the relevant record and sub records but I want the modal form main record to change dependant on the record selected in the subform (which is basically order item history.
I found some code on another site which seemed to work for others but for me I am getting Run-time error 2465 and it doesn't like my reference to 'Me' - is this because it is a modal form?The code I am using is:
Public Function GotoRecord(RecordID As Long) Dim rst As DAO.Recordset Dim strCriteria As String Set rst = Me.RecordsetClone strCriteria = "ID = " & RecordID rst.FindFirst strCriteria If rst.NoMatch = False Then Me.Bookmark = rst.Bookmark
I have a subform which makes a change to a field on the main form. When focus is returned to the main form, the BeforeUpdate and AfterUpdate events fire. Why? I thought from the form's perspective, the subform is just another control.
BTW, I get the same behavior if I modify the field from within the Exit event of the subform control.
In either case, the main form's Dirty event is NOT triggered.
i'm creating a database which holds all animals. i'm trying to make the parents selectable in a subform based on the same table as the main form - this doesn't work for whatever reason ("table is already opened exclusively by another user,..."). it can't just be one field or a query, it needs to be a subform because besides name and eartag i also want to display a small picture of the parent and only the filename is being stored.
i'd really like it to be selectable records in a continuous subform, so the risk of selecting a wrong id is minimized. is there a way around this not being able to use the same table for a subform?
I have a form, a subform and a master unique table. I need the unique table to updated in the following manner: Form has certain fields that need to be assigned to every record created in the subform[id] and [info1] Subform has a unique [caseid], and contains further [info2] but needs to be bound into [id] in the main form. Example of the master unique table:
I've managed to accomplish this with a linked table&subform structure, but the master unique table looks like crap because it collapses the subform values into sub-records in the master table when the [id] is similar. The data is in the rigth place, i just want it not to be collapsed/expanded, but every unique recors shows in the table in the regular format
Hi guys, I have a huge problem with a table I'm currently making and I was hoping you could help.
I have created a field in one of my tables using a Combobox lookup that only allows users to enter one of two options. What I want to do is restrict the other fields that a user can enter data into based on the their selection in the lookup field.
i.e if they select the first option then they can see and enter data into a few additional fields (but not others). Likewise if they select the second option they see/dont see other fields.