me.field
to reference the control. If the code is in a standalone module or in a query then the form must be open and use the unambiguous forms!myform!field
or forms!myform.form.someformoperation
Hi. Are you saying Me,TextboxName doesn't work?
I wan to access an unbound field.
Thanks, I'll try that.If the code is in the form itself, meaning it is form module code, then you could useme.field
to reference the control. If the code is in a standalone module or in a query then the form must be open and use the unambiguousforms!myform!field
orforms!myform.form.someformoperation
I am trying to use a group of optionbuttons to set individual bits of a mask. The buttons are not grouped in an optiongroup because I want them to operate independently rather than as radio buttons. The buttons are unbound because I want to control their appearance based on a single bit rather than the whole word. If they are all bound to the same field then setting any bit will cause them all to indicate False. Each button has an after_update event procedure that sets its bit based on the value of the button after update. What I was asking for was a simple way to refer to the unbound field of the current record of the form.Please provide more detail about what you are attempting, as there may be other solutions.
What you are attempting has probably been done before, and will have a proven, well tested method of doing it. It's difficult to understand what you are attempting from the information you have provided so far.
And like I asked earlier, which I don't understand your response, are you saying using Me.OptionButtonName didn't work?I am trying to use a group of optionbuttons to set individual bits of a mask. The buttons are not grouped in an optiongroup because I want them to operate independently rather than as radio buttons. The buttons are unbound because I want to control their appearance based on a single bit rather than the whole word. If they are all bound to the same field then setting any bit will cause them all to indicate False. Each button has an after_update event procedure that sets its bit based on the value of the button after update. What I was asking for was a simple way to refer to the unbound field of the current record of the form.
That works for getting the state of the button. My question was how to access an unbound field to assign a value. My real problem is that I don't really understand what the context me. means.It doesn't matter if the control is bound or unbound, Me.ControlName should work.
Hi. To assign a value to an unbound control, you simply use something like Me.UnboundControlName=SomeValueYouWantToAssignToItNo that works for getting the state of the buttonAnd like I asked earlier, which I don't understand your response, are you saying using Me.OptionButtonName didn't work?
That works for getting the state of the button. My question was how to access an unbound field to assign a value. My real problem is that I don't really understand what the context me. means.
I have yet to really understand what me. entails and what it does not.
If I understand correctly, you want to set the value of a field in the recordsource, but that field is not bound to any control.My question was how to access an unbound field to assign a value. My real problem is that I don't really understand what the context me. means.
Private Sub cmdAssign_Click()
'Dept is not assigned to a control but it is in recordsource. Only can change it in this code
'Can use Me.Dept to make it easier to understand and leverage intellisense
Dept = InputBox("Type in a value for the Department number", "Department Number")
'The below is only needed for the demo to show the changes immediately in the subform
Me.Dirty = False
Me.subFrmDemo.Requery
End Sub
Private Sub Form_Load()
MsgBox "This form was built without a Recordsource. It is assigning it on load. No fields are property of the form. Must use late binding me!"
Me.RecordSource = "Table1"
End Sub
Private Sub cmdAssign2_Click()
'This will fail since no recordsource at design time
On Error GoTo Errlbl
'Me.Dept will not even compile
Me!Dept = InputBox("Type in a value for the Department number", "Department Number")
'The below is only needed for the demo to show the changes immediately in the subform
Me.Dirty = False
Me.subFrmDemo.Requery
Exit Sub
Errlbl:
MsgBox Err.Number & Err.Description
End Sub
Late binding of me! does work in this case. It does resolve the new field. However, it would be much nicer if there was a way to force the compiler to re-evaluate the bindings of me.This is curious. When is me. computed and is it ever re-computed?
The question arises because I find that if I add a field to my table after the VB module has been created the VB compiler doesn't seem to notice that there is a new field.
In the attached file the one table has two fields cia and mask. Mask was added after the VB module was created and when I try to access me.mask in my VB it fails and generates a compiler error "Method or data member not found"
Is there some way to force the compiler to re-evaluate me.?
Your interpretation and terminology are incorrect. It is not failing to reevaluate the bindings. There is no property yet in the class, you need to do add the Field as a Property to the class. As previously stated, this is done when you add the recordsource to the form. If you create the form with a recordsource and then add a field to your table, you would need to go back to the recordsource of the form and "reselect" it. This will cause any fields that have not been added as a property to get added. Compiling has nothing to do here. ONE MORE TIME. Fields are added as properties to the form when you add a recordsource. This occurs then and only then.However, it would be much nicer if there was a way to force the compiler to re-evaluate the bindings of me. .... Is there some way to force the compiler to re-evaluate me.?
I guess, in a way, @MajP gave you the answer. You could try reassigning the record source of your form when it opens. Maybe that will work.However, it would be much nicer if there was a way to force the compiler to re-evaluate the bindings of me.
@theDBguy and @hkc94501You could try reassigning the record source of your form when it opens. Maybe that will work.