What;s this line of code do? (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 04:36
Joined
Oct 30, 2008
Messages
1,257
Code:
DoCmd.DoMenuItem A_FORMBAR, 2, 1, , A_MENU_VER20

On the next line
Code:
DoCmd.GoToControl "btnStats"

I'm getting (intermittently) error

There is no field named 'btnStats' in the current record.
I'm yet to workout why this sometimes is ok, other times not.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:36
Joined
Oct 29, 2018
Messages
21,358
Hi kirk. Where did this code come from? What was it supposed to do? You're asking about the first line, right?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:36
Joined
Feb 19, 2002
Messages
42,970
I think we need to see the whole procedure. Also, can you describe what happens when the code does something without raising an error?
 

kirkm

Registered User.
Local time
Tomorrow, 04:36
Joined
Oct 30, 2008
Messages
1,257
Thanks for the replies.

This is a older mdb file I attempting to remake as accdb. I've been (mostly) importing components via the New Data Source button. This is causing some things to not work correctly (at times?) . This particular error seems to have come right as I can't duplicate it since yesterday. I didn't write this originally and much of it is hard to understand.


There's main Form and a subform. In reading from a textbox on the subForm the mdb version uses the syntax "ListK.Form_frmTracks!txtNotes". In the accdb version I have to alter this to just "Form_frmTracks!txtNotes".



There is no definition shown for "ListK" - instead you get an Object Browser showing "Project ListK".


How might I figure out what this is - as is may be related to some of the issues?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:36
Joined
Oct 29, 2018
Messages
21,358
Thanks for the replies.

This is a older mdb file I attempting to remake as accdb. I've been (mostly) importing components via the New Data Source button. This is causing some things to not work correctly (at times?) . This particular error seems to have come right as I can't duplicate it since yesterday. I didn't write this originally and much of it is hard to understand.


There's main Form and a subform. In reading from a textbox on the subForm the mdb version uses the syntax "ListK.Form_frmTracks!txtNotes". In the accdb version I have to alter this to just "Form_frmTracks!txtNotes".


There is no definition shown for "ListK" - instead you get an Object Browser showing "Project ListK".


How might I figure out what this is - as is may be related to some of the issues?
Hi. If you're on the main form and want to read the textbox on the subform, the syntax should be something like:
Code:
Me.SubformContainerName.Form!TextboxName
 

kirkm

Registered User.
Local time
Tomorrow, 04:36
Joined
Oct 30, 2008
Messages
1,257
I'm really puzzled by the results I'm getting as things that don't work one day are ok the next.
Anyhow, I can't use that syntax you suggest and wonder why? After "Me." the dropdown list doesn't contain the Form name and running it gives error "Method or Data member not found". What does work is Form_FormName!TextBoxName. Does this suggest that something isn't right ?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:36
Joined
Feb 28, 2001
Messages
26,999
What SHOULD work after Me. would be the name of the control that contains the sub-form. In fact, you should not need to know the name of the sub-form, only its containing control name.

The Form_FormName!TextBoxName syntax should always work if the named form is open.

It suggests that the reference you used was incorrect. However, there is another thought. GoToControl is actually a variant of control.SetFocus and as such, requires that the named control be on the active form. Do you dynamically enable and disable controls on the subject form? You would not be able to set focus to a disabled control.
 

kirkm

Registered User.
Local time
Tomorrow, 04:36
Joined
Oct 30, 2008
Messages
1,257
I'm not sure if any controls are set dynamically. Is there a way to prove that?
This has been very helpful as I've just found an entry under "Me." called "subCDTracks" and Me.SubCDTracks!controlname works. This isn't used anywhere in the database it's always Form_frmCDTracks!controlname. Which is correct/best? (Sometimes the project name & "." was before 'Forms_' but it seems this isn't really needed.)
In Form_Current there's a line
Code:
If Me.CurrentView = conFormView then
conformview is 1. When might this be false ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:36
Joined
Oct 29, 2018
Messages
21,358
I'm not sure if any controls are set dynamically. Is there a way to prove that?
This has been very helpful as I've just found an entry under "Me." called "subCDTracks" and Me.SubCDTracks!controlname works. This isn't used anywhere in the database it's always Form_frmCDTracks!controlname. Which is correct/best? (Sometimes the project name & "." was before 'Forms_' but it seems this isn't really needed.)
In Form_Current there's a line
Code:
If Me.CurrentView = conFormView then
conformview is 1. When might this be false ?
Hi. The proper syntax, I think, needs to include the "Form" part before the control name, e.g. Me.subCDTracks.Form!ControlName But if it works, then I won't complain. If Me.CurrentView=conFormView will be false, if you're viewing the form in Datasheet or Layout view (and Design too).
 

kirkm

Registered User.
Local time
Tomorrow, 04:36
Joined
Oct 30, 2008
Messages
1,257
Thanks for that. Things are coming together nicely. Adding "Form!" works too.
 

Users who are viewing this thread

Top Bottom