Hiding Subform Column in Ms-Access VBA - ms-access

Is it possible to hide subform column using the column number?
Forms("MyForm").Form("SubForm").columns(1).hidden = True

Try with:
Forms("MyForm")("NameOfSubFormControl").Form.Controls(1).Visible = False

Related

How to make a image visible based on a value from a combo box/Text Box in a Access Report?

I have the report mostly working and setup the way I want it but I'm running into a issue where there are two signatures used on the report.. I want the report to show only the signature selected based on a combo box value? The Value is coming into the report but the code I did in VBA in the Event of On Open isn't making my signatures visible... what am I doing wrong? This is what I'm using... My combobox on the report is called cboSelectSignatureToUse and the images in the report is called imgGailSig and imgDanSig. Heres the code I tried with no luck.
If Me.cboSelectSignatureToUse.Value = "Dan" Then
Me.imgDanSig.Visible = True
Me.ImgGailSig.Visible = False
Else
Me.ImgGailSig.Visible = True
Me.imgDanSig.Visible = False
End If
Can use OnLoad event if report is filtered to a single record.
If multiple records are pulled, use OnFormat or OnPrint event of section that contains the image control.
Consider:
Me.ImgGailSig.Visible = Me.cboSelectSignatureToUse.Value = "Gail"
Me.imgDanSig.Visible = Me.cboSelectSignatureToUse.Value = "Dan"

Access: Fill in data (date) from another when entered and empty

Working with MS Access 2016.
I have a form with multiple textboxes. I want one of my textboxes (tbx_outTSDatum_BQC) to be automatically filled -if entered and empty- with the value of another textbox (tbx_inTSDatum_BQC). This code does nothing:
Private Sub tbx_outTSDatum_BQC_Enter()
If Me.tbx_outTSDatum_BQC.Value = Empty Then Me.tbx_outTSDatum_BQC.Value = Me.tbx_inTSDatum_BQC.Value
End Sub
Changing the event from Enter() to GotFocus() does not help. How can I get this working? Thank you.
It is Null to check for:
If IsNull(Me!tbx_outTSDatum_BQC.Value) Then
Me!tbx_outTSDatum_BQC.Value = Me!tbx_inTSDatum_BQC.Value
End If

How to programmatically select a value in combo-box?

Good Day all. I have a quick question. I have an openargs value that I'm am trying to use to show up in my combobox (cmbMemberName) on return from another form. The combobox populate the underlining subform. I just can't seem to get the right method. I can't use recordsource cause that would filter out the rest of the records. Rem: I just want the focus on the updated record and loaded into the combobox upon return. Here's the last method I tried.
If Nz(Me.OpenArgs) <> 0 Then
Me.cmbMemberName.SetFocus
DoCmd.FindRecord Me.OpenArgs
MsgBox (Me.OpenArgs)
Me!cmbMemberName.Dropdown
Else
....
The error occurs on the DoCmd. Any suggestions. Thanks. I could load the entire sequence, but don't think that would be necessary.
First you have to set the value of the combo box. Assuming your openargs matches the bound column of the combo box that should simply be
Me.cmbMemberName = Me.OpenArgs
After that you need to get you subform to populate based on the combo box value. Assuming you have set the subform to properly read the value you just need to requery it
Me.MySubForm.requery

Filter on Subdatasheet

In Access 2003, I have form with a a datasheet and an embedded subdatasheet. I would like to apply filters to both the main and sub datasheets. First, I build a filter string for the main datasheet strWhere, and one for the sub datasheet sdsWhere. Next, from the From object of the main datasheet, I set .filter=strWhere. Then, I set a filter on the subdatasheet's Form object. Basically:
With Me.Controls(dataSheetName).Form
.Filter = strWhere
.FilterOn = True
With .Controls(subsheetname).Form
.Filter = sdsWhere
.FilterOn = True
End with
End with
The problem is that the subdatasheet is only filtered for the first record of the main datasheet. Looking at the RecordSet of the sub datasheet, it only contains the child records of the first record in the main datasheet. I cannot find the other records anywhere.
I know that it should be possible to filter all subdatasheet records, because from the Access interface, placing the cursor in the desired value, and selecting Records>>Filter by Selection has the desired effect. (Except that records in the main form with have empty subdatasheets show, and I would like them to not show)
Use a query. Make a query joining both the Main and the Sub datasets. Filter on the query. I don't really see any other efficient way.
I'm an idiot - figured it out, of course just move the subdatasheet's Recodset position, and then apply the filter until eof. But we need to goto the first record, first otherwise it will miss the records before the record the user is currently positioned at. And make sure that subdatasheetexpanded is true.
Dim mainDS As Form, subDS As Form
Set mainDS = Me.Controls(dataSheetName).Form
If mainDS.SubdatasheetExpanded = False Then
mainDS.SubdatasheetExpanded = True
End If
mainDS.Recordset.MoveFirst
Do While Not mainDS.Recordset.EOF
Set subDS = mainDS.Controls(sdsheet).Form
subDS.Filter = sdsWhere
subDS.FilterOn = True
mainDS.Recordset.MoveNext
Loop

MSAccess - populate text box with value from query

I have a combo box and several text boxes on a form. When I select a value from the combo box I want it to run a query based on that value and populate the text boxes with the data returned by the query. The query should only return one record and the textboxes correnspond to different columns in that record.
I have this code:
Private Sub cbo_equip_loc_Change()
Dim location As String
Me.cbo_equip_loc.SetFocus
location = DLookup("NAME", "Query1", "position = '" & Me.cbo_equip_loc.SelText & "'")
Me.Text51.SetFocus
Me.Text51.Text = location
End Sub
But I get this error: "This property is read-only and can't be set"
Any ideas?
Solved: Im an idiot.
I had some value in the Control Source from something I was trying to do before. Removed that and it worked!
There is no need to do this:
Me.Text51.SetFocus
Me.Text51.Text = location
it is true that the text property is only available when the control has the focus, but the value property is available without any focus, or Access VBA is quite happy with just the name of the control:
Me.Text51.Value = location
Or
Me.Text51 = location
Textbox Text51 is locked, set property Locked to False.