MSAccess 2010 - Subform in a subform not showing fields - ms-access

I have a database with a main form, and on the main form is a subform. The subform also has a subform, which gets hidden unless a field on the first subform (the parent subform) is set to "ticket," at which time the second (child) subform appears. I got it working beautifully, except that the child subform appears blank, with no fields or labels on it. Just a background color that I set on the child subform itself.
I am using the following code in the AfterUpdate
Private Sub EventTypedd_AfterUpdate()
'Make the Ticket subform visible once EventTypedd is set to TICKET
If Me.EventTypedd.Value = "Ticket" Then
SBFCreateTicket.Visible = "True"
Else
SBFCreateTicket.Visible = "False"
End If
End Sub
Can anybody suggest possible reasons why the subform won't show the fields? The form itself shows up as it should, and the background color of the form shows up, but none of the fields or the field labels show up, and I can't figure out why. Anyone know why, or have a suggestion? Thanks!

I would like to ask a question or two but don't have the Stackoverflow kudos to do this. The issue maybe that you are not refreshing the final subform. So that when you go into the main form record without touching it, the final subform query returns zero records.
You then set flags on the top form and you should see results but the subform may not have re queried.
Try...
SBFCreateTicket.requery '<<< New line before your original code.
If Me.EventTypedd.Value = "Ticket" Then
SBFCreateTicket.Visible = "True"
Else
SBFCreateTicket.Visible = "False"
End If

Okay, I figured it out. Apparently, the AllowEdits on the second subform was set to NO, and I'm not sure why. As soon as I set it to YES, the form shows up and everything works perfectly. And as usual, as soon as I solve one problem, another one crops up a little farther down the workflow process, but that's a subject for another thread. Thanks to the ONE person that tried to help me out, anyway. :)

Related

How to keep focus after requery in MS Access?

I am using the following code in VBA to keep focus on a certain recordset even after requery :
With Forms!frmMain!frmMainSub
strControlName = .Form.ActiveControl.Name
lngCurrentPos = .Form.Recordset.AbsolutePosition
.Requery
.Form.Recordset.AbsolutePosition = lngCurrentPos
.Form.Controls(strControlName).SetFocus
End With
The problem with this code is that the subform is in datasheet view and is usually sorted by a field. Since the code above records the absolute position on dynaset- or snapshot-type Recordset object, it cannot keep track of the sorted datasheet.
Is there a better way to keep focus on a specific field after the form is requeired?
Edit:
This question is not a duplicate because there are answers about keeping the focus from the same form. The problem is that I am in a different form and also I want to preserve focus even when filter is applied to one of the fields.

Populate textboxes with value from listbox selection on child form

I realise this question has been asked before and I have tried numerous suggestions, but I guess I am just too much of a novice when it comes to VBA coding.
Here is my scenario:
I have an Access 2007 "Application" with a few forms. On the main form, I have 2 text boxes. For simplicity let's call them textbox1 and textbox2.
textbox1 is used to enter a style code. a button on the main form then opens another in modal/dialog mode and runs a query with the style code as the where clasue. the modal popup gives me a list box which is populated from the database based on the query that was passed. I then need to select one of the products in the list and upon closing the popup, populate textbox2 with the brand (column2 in the list from the popup) number.
Please remember that I am a novice. Any help would be greatly appreciated.
I would put a button on the second form, and in the _Click() function, put something like this
If ListBox1.ListIndex = -1 Then
MsgBox "Nothing Selected!"
Exit Sub
End If
UserForm1.TextBox1.Text = ListBox1.List(ListBox1.ListIndex)
Unload Me
Where ListBox1 is the list box containing the content you need the user to select from, where UserForm1 is the name of the calling form, and TextBox1 is the name.
Explanation
The ListIndex property of the list box returns the index of the selected list item. If nothing is selected, it returns a -1.
To reference an item on one from from another, you reference the form, the object and the property.
In The example I gave, the form is UserForm1, the object is TextBox1 and the Property is Text. While typing, intellisense should auto complete the object and properties once you type the period.

if checkbox is marked, then create msgbox with form value in access

So I have an access form based on a table. The form has a list of colors and a yes/no checkbox next to it. If the user marks the checkboxes then clicks a button, i want a msgbox to appear to show all the colors next to the marked checkboxes. Here is the code I currently have, it does not run if I click the button a second time. It also sometimes only shows the first color and is buggy in general.
Form looks like this
Red x
Blue
Green x
Yellow x
Code looks like this
private sub command5_click()
dim rs as dao.recordset
set rs=me.recordsetclone
rs.movefirst
do while not rs.eof
if rs!checkboxes = true then
msgbox rs!color
end if
rs.movenext
loop
set rs=nothing
end sub
You need to add Me.Dirty = False at the top of command5_Click. Requerying the recordset is overkill - you lose your scroll position and your current record.
When you have a continuous form, data is written out to the database when focus is moved from the current record to a different record. This does not happen when you move focus to a control in the header or footer. This is by design, as it is a useful feature. Here's why:
Suppose you had a 3rd field in your database, a text field called "essay" where you could write a 10-line essay all about the color. The field is too big to show on the continuous part of the form, so you add a bound textbox to the form footer. As you move up and down through the color records, the essay for the current color will show at the bottom of the form. And it will be editable. When you click on the Essay textbox, the current record is still being edited. The current record can have bound controls in the header, detail and footer, and edits in any of those places will all be written to the DB simultaneously.
When you move focus to an unbound control (such as command5), it's no different. The current record is still the current record, even though none of its bound controls currently have the focus.
Whenever you want the current record to remain the current record, but to force its edits to be written to the DB, you use Me.Dirty = False.
As to why command5 only works the first time you click it? I have no idea!

Subform losing focus when Adding new record

My DB is split into Front and Back. I have three tables that I am working with in this problem; tblMain, tblDetail, tblNote. I know that the number of records is relatively small but I am designing this for long term use. I have a bound form (frmMain) for tblMain that has a subform (subDetail) for tblDetail. SubDetail has a subform (subNote) for tblNote. When I click a button on the main form, frmMain, the subDetail form becomes visible and allows me to add a new record. I copied the button and the VBA to subDetail so I could do the same thing for adding a record to subNote if needed. However, after the record is created, the subNote form disappears and focus is returned to subDetail. If I move to a new record then back, the subNote form becomes visible and shows an empty record except for the PK. I've checked all the properties of both subDetail and subNote. They are the exact same except for the OnCurrent event for subDetail. I have the following for the subDetail OnCurrent Event.
'Hide subform if no records
Private Sub Form_Current()
Me!ctrlmlsID.SetFocus
With Me!subNote.Form
.Visible = (.RecordsetClone.RecordCount > 0)
End With
End Sub
This hides or displays the subform, subNote, depending on if there is any records or not. Any help in figuring out this behavior would be appreciated.
Here is the code for adding a new record to subNote upon button click.
If Me.Dirty Then Me.Dirty = False
Dim AddTransID As String
AddTransID = Me!ctrlID.Value
Me!subNote.Visible = True
Me!subNote.SetFocus
DoCmd.GoToRecord , , acNewRec
Me!subNote.Form!ctrlID = AddTransID
Me!subNote.Form!ctrlType.SetFocus
I've used breakpoints and the adding record works just fine. It's just the subform going invisible again and the focus being changed back to the parent that is the issue because it won't allow those notes to be added.
I get the impression you are fighting Access here.
You normally do not need a button to create a new record using a properly bound subform with AllowAdditions = True. That will happen automatically.
The problem you are running into may stem from the fact that the new records don't really exist yet until saved (as you observe there is no PK value). So the logic to hide subforms isn't going to work. If you insist on staying with this approach you might try
.Visible = (.RecordsetClone.RecordCount > 0 or .NewRecord)
But I think your life will be easier if you remove the buttons and code you have mentioned and let Access do what it is good at doing. Make sure your subform data binding properties are set right.

How to put a label as link at the end of coloumns in a subform (Datasheet) in Access 2000?

I have a database created in access 2000. A form with a subform (datasheet - defaultview) in it. I have added a label at end of the coloumns in subform and given hyperlink to open the object present in database itself. But when the form open nothing is visible after the coloumn ? I got four coloumns and had hide two columns via onload event of subform. the code is below
Me.SubGroupname.ColumnHidden = True
Me.GroupName.ColumnHidden = True
Me.BNFno.ColumnHidden = False
Me.BNFno.ColumnWidth = -2
Me.SubGroupName1.ColumnWidth = -2
How can I make it visible so that it will appear as a link at each row ?
Please help me.
If I understand you properly, you cannot use Datasheet view to display a control at the end of a row. Switch to Continuous Forms view, it will give you more control, but you will have to work a little harder to get a nice layout.
Alternatively, add a click event to one of the existing columns.