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

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

Related

Make field in Access report (in)visible based off another field

I'm trying to have a text box show/not show based off the value in another field on an Access report and I can't figure out if my VBA is wrong of if I'm using the wrong trigger.
I can't get this to trigger:
Private Sub Report_Load()
If Me.Bill = 64 Then
Me.Code64.Visible = True
Else
Me.Code64.Visible = False
End If
End Sub
I've tried adding ".value" after "Bill" and putting quotes around "64"
I can't for the life of me figure out how to get it to trigger.
That code would have to be in Format event of section that contains the control. Event only runs for direct to printer or PrintPreview, not ReportView.
Alternatively, could just have expression in textbox and eliminate VBA.
=IIf([Bill] = 64, Null, [Cod64])

Autopopulate textbox on combobox update in MS Access

I am using a combobox in Ms Access, which on change will populate other textboxes. The code is like this:
Private Sub Combotxt_Change();
Me.Qtypetxt = Me.Combotxt.Column(1);
Me.PFtxt = Me.Combotxt.Column(2);
End Sub
In this, the first textbox i.e. Qtypetxt gets updated whereas PFtxt doens't.
Kindly help.

Access 2007 continuous form - only matching row editable

Good afternoon,
I've got a continuous form that displays records for any number of selected employees. I'd like for only that employee's row (or more specifically a particular text box in their row) be editable and no others.
I thought about doing something like this.
Private Sub Form_Load()
If Me.txtResponse <> [Forms]![Home].txtEmployeeName Then
Me.txtResponse.Locked = True
End If
End Sub
and I get an error that I entered an expression that has no value - and it highlights the me.txtResponse.
I don't know if i'm barking up the wrong tree or if this is even possible in a continuous bound form. Any ideas?
Form_Load is too early for that code. Move it to the Form_Current event and it will run when first opened and again with each record navigation. You'll want to add
Else
Me.txtResponse.Locked = False
in their to allow changes when a match is made.

Make fields visible in MS Access form as certain fields are completed

I am building a form In MS Access for users to input data but there are too many possible fields. Most of the time only about half the fields will be used.
I thus would like to have certain fields appear only depending on what the user inputted on a prior given field.
Ex: user enters project number, title, then he checks a "yes/no" engineering. since he checked it this means engineering is impacted so a dozen fields that the user will have to fill out appear.
Is this possible:
1)without VBA
2)with VBA
Probably not possible without VBA.
With VBA for example:
Ensure your form is in Design view
Right click on your Combo Box, Build Event, Code Builder
This opens the code behind your form. It drops you into the default code for the BeforeUpdate event. We want the Change event instead, so at the top right change the drop down from BeforeUpdate to Change. This will give you a bit of code like this:
Private Sub Field1_Change()
End Sub
Inside here, you want to check the value of the combo box and hide fields as required:
Assuming the name of your combo box is Field1 (yours of course will be different), you add some code so it looks like this to hide Field2:
Private Sub Field1_Change()
If Field1.Value = "Yes" Then
Me.Field2.Visible = False
End If
End Sub
Note you need to know the names of all your fields - this is in the Other tab, Name field in the properties box (F4). You should give all of your fields sensible names so you can understand what is going on in the code.
For a check box, follow exactly the same procedure, but you probably need to use the Click event. Just experiment.
Sample check box code:
Private Sub Check5_Click()
' Note: vbTrue = -1
If Me.Check5 = vbTrue Then
MsgBox ("Ticked")
Else
MsgBox ("Not Ticked")
End If
End Sub
I have a form that will show certain fields after a list box value is selected. I use the AfterUpdate function. It has worked so far. My code is below. ProjectName and ProjectNumber are fields you only want displayed if Engineering is selected. OtherName and OtherNumber are fields you only want to show if it is a "NotEngineering" project.
Insert this code by clicking on the Field that selects the project type, go to the Event tab on the property sheet, and click "After Update" and choose code builder and paste in VBA.
Private Sub ProjectType_AfterUpdate()
If ProjectType.Value = "Engineering" Then
Me.ProjectName.Visible = True
Me.ProjectNumber.Visible = True
Else
Me.ProjectName.Visible = False
Me.ProjectNumber.Visible = False
End If
If ProjectType.Value = "NotEngineering" Then
Me.OtherName.Visible = True
Me.OtherNumber.Visible = True
Else
Me.OtherName.Visible = False
Me.OtherNumber.Visible = False
End If
End Sub
There is a way to do not-quite-this without VBA. I'd definitely recommend VBA though, because you can do a lot more with it.
Rather than hiding, try disabling the unnecessary fields with conditional formatting by expression.
right-click on the control you want disabled.
go down and click on 'Conditional Formatting'
Add a new rule
Select 'Expression is'
example:
[fld1]="yes"
hit the disabled box
click ok
click ok
now the control you've selected will disable if field 1 has "yes" selected.
I have the same problem and I did the following:
Private Sub Field1_Click()
If Field1 = "Yes" Then
Me.Field2.Visible = True
Else: Me.Field2.Visible = False
End If
End Sub
but now I have other problem, when I change record, the field that I choosen to be visible in the last record is now visible on the current record, although I have not choosen any option.
Thank you,

How to make Dlookup textbox writeable

I am working on forms and made a single form for data entry and search ( data extraction) but the problem is that i used Dlookup formula on some textboxes for ease in data entry but when i attemp to search access doesn't show data on that textbox and shows the error that the object is read only.
How can i get the textbox show data as well as have Dlookup formula?
Kindly help.
Many thanx
You can set the textbox value by code instead of putting the DLookup into the data source of the textbox.
Putting it into the data source means that you can't edit the textbox at runtime, as you experienced.
But you can set the value once in the Form_Open event, for example:
Private Sub Form_Open(Cancel As Integer)
Me.TheTextBox = DLookup(...)
End Sub
This will cause the textbox to be filled automatically when the form opens, but the textbox is editable and you can overwrite the value.