Forms and Subforms in Access 2003 - ms-access

I have only one table and I would like to create a form for the users to populate the table easily. There are at least 5 fields in the table that only needs to be completed if a certain type of inspection (Fire) is selected from a drop down list and is left blank otherwise.
I would like to create a subform that will only pop up when inspection type "Fire" is selected from the drop down list in the main form. How can I do this?
I used the wizard to create the form and I am stuck because I really don't know VBA. So far, I went to the inspection type field on the form, clicked on "Properties", then clicked on "After Update", then selected the Macro that I created to open the subform when the inspection type = "Fire", but it isn't working.
What happens is the subform gets opened up no matter what type of inspection I select, then the ID number on the subform doesn't correspond to the main form (the subform ID will remain on id#1). Also, when I do input data in the subform, the information ends in the next record.
I was wondering if that is happening because I am using both the form and the subform to enter data into the same table. I hope this is a clear explanation of what I want to do.

Just to try to improve a bit on Kovags excellent proposition:
Sub InspectionType_AfterUpdate
Subform1.Visible=(InspectionType.Text="Fire")
End Sub
Sub Form_Current
InspectionType_AfterUpdate
End Sub

Just change this code to adapt your needs and add it to the Change Event of the Inspection Type textbox:
Sub InspectionType_Change
if InspectionType.Text="Fire" Then
Subform1.Visible=True
else
Subform1.Visible=False
endif
End Sub

If the fields are on the same table then I'd suggest placing the fields on the subform onto the main form. Then making them visible or not depending on the state of the combo box.
Using a subform gets a bit more complex as, among other things, you will need to save the record in the main form before opening the subform. Otherwise the subform won't be able to update the record and will give you a locking message.

Related

Error 3251 when setting record source for subform

I've been having this error where I am unable to set the record source for a subform.
Just a bit of background, the form in question is structured as such: frm1View is my unbound main form which contains 2 subforms, subfrm1Particulars and subfrm1Datasheet. The issue is with subfrm1Particulars, which itself contains 2 subforms in a tab control.
I am attempting to change the recordsource of my subform in subfrm1Particulars dynamically, based on the records found in the other subform (one sub form displays courses completed and the other displays courses scheduled; the idea is to remove scheduled courses they have already completed from that sub form view).
I am using the following code to do this dynamic recordsource change. The code is contained in subfrm1Particulars(which contains subfrmScheduledCourses)
strSQL = *blah blah blah where etc etc not like etc*
Me.subfrmScheduledCourses.Form.Recordsource= strSQL
I've checked numerous times, my subform control name is correct (although my subform shares the same name as the control, so maybe that's the issue). I have almost the exact same form configuration in another form, with the same code (i.e. the same recordsource and SQL statements and method of assigning recordsource) and it works perfectly, so I can't tell why this isn't working.
It gives me an error 3251. I'm running this in the On Enter event of the subform control (in both of my forms where this particular code appears).
Any help at all is much appreciated!!
Referring to subform objects can be tricky, especially from other subforms. Try calling the object differently:
Forms!frm1View!subfrm1Particulars.Form!subfrmScheduledCourses.Form.RecordSource
What this does it begins referring to form objects by navigating from mainform to subform to the desired area.

Requerying a subform with unbound controls

I have a subform with unbound image controls that are being populated through code. I am using this subform to display search results when a SEARCH button is clicked. The problem is that I cannot refresh/requery the subform to reflect the current search status, except when I close and open again the form (subform) as a standalone/popup.
I tried this but failed to requery:
With Me.F_Person_Thumbnails_control
.SourceObject = Forms.F_Person_Thumbnails
End With
I will appreciate any help.
Joseph
Try accessing your unbound subform from the parent form.
' To Requery
me.mySubForm.form.requery
' To set a TextBox
me.mySubForm.form.controls("MyTextBox").value = "Test"
You can also access fields from your subform using the form.parent object, although I personally consider this a messier approach - since you are generating errors if the subform is opened by itself. Using the above approach lets you re-use the subform in other places in your database, with different logic (if required). Accessing parent object:
Me.MyTextBox.Value = Me.Parent.Form.Controls("IDNumber").Value

need to refresh subform based list box selection in access 2007

Preface: I have a form which has tabs. In one of the tabs, I have a list box, a button, and a sub-form. The list box is populated from two tables and has a bound column.
Needed: I need the sub-form to edit existing records of one of the tables the list box is built on and append records to the same table on button click. The sub form is to be linked to the non-bound column of the list box. Please help.. I have tried a few things in Vb but could not complete..
--Chegu.
I am not sure if I understand you correctly, but if you want to select a line in the listbox, edit the respective record in the underlying table and then save the record and update the listbox, you could work along those lines:
The listbox should not be linked, neither should the subform.
Create a procedure
Sub UpdateSubform()
subform![id]=listbox!changetableID]
End sub
In the OnLoad event of the form and in the OnChange event of the listbox call this procedure
In the afterUpdate event of the subform:
Private Sub Form_AfterUpdate()
me.parent.requery
End Sub
I didn't check this out myself, because I am away from my access - but it should work along those lines.
If thats not what you are looking for, please edit your post and at least post the information whats in the listbox and where your subform should link to.

Access 2007 Filter Subform Based On Field In Main Form?

I was tasked with creating a simple app to maintain a user's collectibles collection using Access 2007. There were some requests, which I have created and implemented. Those being:
One main form listing all of his collectibles
That same main form has a tabbed control below, with each tab containing a subform that in effect "filters" data based on different criteria from the main form. For example, the 1st subform takes the name of the collectible figure in the main form, and displays all other records using that name in the subform. In other words, if the figure is "Darth Vader", the subform would list all collectibles that have the name "Darth Vader".
I have created the application as per user request, but there is one thing that is bothering both of us so far. The subform's first record is the same as the main form. We both find that redundant, and annoying. Granted, my Access skills is weak at best, so this may be a simple fix, but is there a way to remove the duplicate record in the subform? I have tried implementing a where clause in the subform stating to not include the "Figure ID" in the main form. Problem is, it is acting like a Parameter prompt, asking for the main form's FigureID when I open the subform, or the main form. If I type in the Figure ID, it works, but the prompt is something that is obviously not wanted.
FYI:
The main form is based on a query that basically selects all records from the "Figures" table and other related tables
The subform was created when I dropped the subform control onto the tab control, where I linked the necessary master and child fields
Say you have a form named frmMain. That form includes two fields in its record source: FigureID; and Figure_name. The form also includes a text box control named txtFigureID which is bound to the FigureID record source field.
frmMain also contains a subform control based on a form named frmSub. The record source for frmSub also includes FigureID and Figure_name fields. The subform control's link master/child field property is Figure_name. Therefore frmSub will display all the rows where Figure_name matches the corresponding value in the frmMain's current record.
Now, if you want frmSub to exclude the specific record (as identified by the unique FigureID value) which is the current record in frmMain, add a WHERE clause to frmSub's record source query:
WHERE FigureID <> Forms!frmMain!txtFigureID
I'm only guessing here, but hope that description is close enough to your actual situation to be useful. If not, show us the SQL you're using as the record source for your subform.
Edit: You get the parameter prompt only when you first open frmMain. Afterwards, you can navigate between records in frmMain, and frmSub shows you only the records you want to see ... without asking you again to supply a parameter value.
The reason that happens is because the subform loads before its parent form ... so a control on the parent form is not available when the subform loads.
I think the cure may be to save the subform without the WHERE condition in its record source. Then, when the main form loads, it can re-write the subform's record source to include the WHERE condition.
So, in frmMain's load event:
Private Sub Form_Load()
Dim strSql As String
strSql = "SELECT FigureID, Figure_name FROM YourTable" & vbCrLf & _
"WHERE FigureID <> Forms!frmMain!txtFigureID"
Debug.Print strSql
Me.subformControlName.Form.RecordSource = strSql
End Sub
Watch out for subformControlName. It's a control, not a form. The subform control may have the same name as the form it contains. But it could be a different name.

ms access auto fill main form based on focus of subform

I have a data entry/editing form with two combo boxes (Name and Group).
Each Group correlates to multiple names but each name is in only one group.
At the bottom of this form is a subform which is a continuous form
displaying a query of the associated table filtered based on an
unbound combo from which you select the group.
Basically, you choose which group you want to see and it displays a list of all the Names in that Group.
I want to make this form able to add and delete Names from the table (which it does with buttons already), but I also want to be able to select a Name from the subform and have the main form focus on that entry and auto fill the two bound combos.
And then from there I would like to be able to edit and save that entry or just delete the entry.
Similarly, I would like to be able to add a new entry without worrying about writing over a current entry. Access might do this automatically; if this is the case:
Is it even possible to edit an entry without deleting and then replacing it?
I also want to be able to select a
Name from the subform and have the
main form focus on that entry and auto
fill the two bound combos.
To do that, you can do a FindRecord on the main form's recordset, using the ID from the subform. The form will move to the correct record. From the subform's OnCurrent Event:
Forms!MyMainForm.Recordset.FindFirst "MyID = " & desiredRecordID
or
Forms!MyMainForm.Recordset.FindFirst "MyID = '" & desiredRecordID & "'"
Similarly, I would like to be able to
add a new entry without worrying about
writing over a current entry.
To do that, execute the following code:
DoCmd.GoToRecord acDataForm, "MyMainForm", acNewRec