Continuous form only referring to the first record - ms-access

I have a continuous form - one of the fields on the form is RecordID.
I have a label on that form, that when clicked should produce a message box with the RecordID in it via VBA:
MsgBox Me.RecordID
The label is reproduced on each row of the Continuous Form, but will only reference the first record. Even though I can see the RecordID field is different in each row of the form, I always get the same result, in this case 80029.
What's up with that?

Me.RecordID refers to the RecordID of the current record, as indicated by the black triangle in the record selector:
A Label control on a form cannot receive the Focus, so when you click on the label in another record the current record does not change and you keep getting the same RecordID. Note that if you put the same code into the Click handler for a textbox (or some other control that can receive the Focus) then the current record will change and you'll get the RecordID of that record.

Related

Clear out dropdown value once another drodown value is changed in vba access?

I have three combo box controls(MFG, Code, and GrpID) in my VBA access form. Once the user selects an option from the first combo box (MFG), rest of combo boxes give me available options. But I need to do some validation i.e. what if the user decided to change the value of first combo box? The values of rest combo box should be cleared. All I need to do is once the first combo box is changed the second and third combo box need to be cleared out or at least set to focus on them so that users will realize that they can't use old values as first value is cleared in the first combo box. I added a code block 'AfterUpdate for first combo box as shown below:
Private Sub MFG_AfterUpdate()
Code.Value = " "
GrpID.Value = 0
End Sub
The problem after writing above code is: they don't get empty until they(Code and GrpID) get clicked. In other words, I need to click them to empty them every time I change the value of MFG. Can anyone direct me how do I clear them or at least focus them?
Set the combo to null to wipe any displayed value in them;
Me.Code = Null
Me.GrpID = Null
This assumes your combo controls are called the same as your field names.
Edit for clarity: Including the Me. makes sure your are changing the form control values. If your field names are the same as the controls then Access will change the underlying field values, and as you have discovered on your form these aren't reflected until you click in that fields bound control.

Tab to first field of subform in MS Access

In MS Access, how can I tab form the last field of the main form to the first field on the first subform? As it is, wen I tab form the last field of the main form it moves to the last used field (usually the last field) of the first subform. Similarly, from the last field of the first subform it tabs to the last used field og the second subfor in stead of the first field on the second subform.
Not a big thing, but I reckon it should be relatively easy to address.
Try to use On Enter and On Exit subform events for set focus on required field in main form

Removing the selected record from a combobox

I have an access form with a combobox for Suppliers. I have a '...' button control next to the combobox, which opens a new supplier form if the combobox is empty or goes to the selected supplier if its occupied. My issue is if the user selects a record and then realises its wrong and wants to add a new supplier.
When deleting the supplier name, either by delete button or backspace, the record seems to be still selected. However, the '...' button doesn't work. Trying to navigate away from the record means that I get an error saying You must enter a value in the Order.supplier_ID field.
Is there any way of clearing the selection easily?
Can I clear the selection without this error? Allowing the user to navigate away from the combobox and select the '...' button
Will I need VBA, and where do I even start?
Something like this should help you :
store the index of selected item
change it to the next one or the previous one
remove the item that was selected before
Here is the code :
Dim SelectedITM As Long
With Order.supplier_ID
SelectedITM = .SelectedItem
If SelectedITM <> .ListCount - 1 Then
.Selected (SelectedITM + 1)
Else
.Selected (SelectedITM - 1)
End If
.Items.Remove (SelectedITM)
End With

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!

copy value entered in unbound textbox to label after pressing button

I have an unbound text box on my form which the admin can enter a date of when records were last updated. I want this date to be copied to a label after pushing a button so that it holds the date instead of it do disappear after closing the form.
does anyone know if this is possible and how it is possible?
For creating a variable that can be used AFTER the form is closed:
Create a new module (in code window, click 'Insert | Module'
Insert the variable name(s) and types you want available everywhere. i.e.
Global dtLastUpdated As Date
Global strSaveSomeName As String
Save the module as mdl_Globals
Add code wherever needed to set the variable, then can reference anywhere.
If for use during the form, use the following: where 'lblForUnbound' is the Label field and 'txtUnbound' is your unbound text box
Me.lblForUnbound.Caption = Me.txtUnbound.Text