• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Set continuous form textbox labels (1 Viewer)

howling_muffin

New member
Local time
Today, 03:51
Joined
Jul 29, 2020
Messages
11
I have a continuous form with a textbox, and I'm setting Form.RecordSource to the data I need displayed, but nothing's displaying.
I'm having a hard time understanding how to assign query data to an element in a continuous form. I would usually do Me.LabelName.Caption = "Assign value." but here I want each value in the query data to be in another LabelName.
I've searched a long time but there doesn't seem to be much on continuous forms.
Any help on this?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:51
Joined
Oct 29, 2018
Messages
12,394
Hi. Not sure I follow. You said you want to assign data to textboxes, but you use "LabelName.Caption" in your code. Why can't you just bind the form to the query?
 

howling_muffin

New member
Local time
Today, 03:51
Joined
Jul 29, 2020
Messages
11
Hi. Not sure I follow. You said you want to assign data to textboxes, but you use "LabelName.Caption" in your code. Why can't you just bind the form to the query?
Sorry if I haven't explained well...
The textbox has a label, and I want each label to display the query data (which in this case is a name), so that the user can fill in the textbox
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 03:51
Joined
Jul 9, 2003
Messages
11,972
I'm not following you either.. However I think you should use a text box displaying information from the query instead of trying to assign information "a name" to a label. Gather the name with the same query, and show it in a text box adjacent to the text-box you want to fill in
 

howling_muffin

New member
Local time
Today, 03:51
Joined
Jul 29, 2020
Messages
11
show it in a text box
How do I do that? Normally to set the value of a textbox I would use something like
Code:
Public Property Let Name(value As String)
    Me.txtName.value = value
End Property

but because this is a continuous form I haven't got a value, I've got a SQL string which I think I'm supposed to be setting as the RecordSource, but don't know how or how to tell RecordSource to apply its data to my Name textbox and not any other element on the form...?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:51
Joined
Oct 29, 2018
Messages
12,394
Hi. Are you able to post a sample copy of your db with test data? We are all having a hard time understanding what you're trying to do. There should be no code necessary.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 03:51
Joined
Jul 9, 2003
Messages
11,972
I've got a SQL string

The SQL statement will provide you with a set of Records. To test this create a query based on your SQL statement. This query should list the records you expect to see, if it doesn't, you need to adjust it until it does.

Once you have the query working OK, create a form based on that query. The form will automatically generate text boxes which will show the data provided by the query.

Change the properties of the form so that it displays in continuous view and it will list the data for you.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:51
Joined
Feb 19, 2013
Messages
12,528
But don't know how or how to tell RecordSource to apply its data to my Name textbox and not any other element on the form...?
you set the textbox controlsource to the name of the field you want to display.

Assuming your recordsource is the name of a table or query - have you tried using the wizard to create a form? simply click on the table or query (don't open it) then in the ribbon select Create>Form. Alternatively have you looked at one of the many templates to see how it is done there?
 

howling_muffin

New member
Local time
Today, 03:51
Joined
Jul 29, 2020
Messages
11
you set the textbox controlsource to the name of the field you want to display.

Assuming your recordsource is the name of a table or query - have you tried using the wizard to create a form? simply click on the table or query (don't open it) then in the ribbon select Create>Form. Alternatively have you looked at one of the many templates to see how it is done there?
Well it's not really the same question but I never got the hang of making a query with parameters that can be passed in programmatically, and I'm trying to pick my VBA battles over here :).

Which templates are you referring to?
 

howling_muffin

New member
Local time
Today, 03:51
Joined
Jul 29, 2020
Messages
11
you set the textbox controlsource to the name of the field you want to display.
So the Form.RecordSource is set to the sql string that contains the query, and the Textbox.ControlSource is set to the name of one of the fields returned in the query. Is that it?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:51
Joined
Feb 19, 2013
Messages
12,528
pretty much

with regards templates go to file>new - they are all listed there. Since I don't know what your app is supposed to do I can't suggest a specific one - they are all in separate folders, depending on the type of app (contact management, financial planning etc)
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:51
Joined
Feb 19, 2002
Messages
29,690
I suspect that since you know about Property Let, you have some programming background but are new to Access. Access is a Rapid Application Development (RAD) tool and it does a lot of stuff for you. Writing code is a big part of a professionally developed application but it is your LAST stop for basic stuff rather than your first. Bound forms are the heart and soul of Access and it would be wise to embrace them. To bind a form to a recordset use the Form's RecordSource property and enter a table name (not desirable) or a query(desirable). The query should have criteria to limit the rows returned (but that's a different lesson). Once the form is bound to a recordsource, you can bind individual controls by choosing a field name from the bound recordsource in the control's ControlSource property. Typically, when building a form, I create a query that selects the columns I want and then I let the wizard build the form in Single, Continuous, or DataSheet view. Then I move stuff around and make it pretty. Everything needed to retrieve and save records already exists. Then you would add code in the Form's BeforeUpdate event if you needed to to any validation. The Form's BeforeUpdate event is the flapper at the bottom of a funnel. NO RECORD EVER GETS SAVED if it doesn't go through the Form's BeforeUpdate event first. So, this is the GoTo place to control whether or not you want to save a record. Cancel the update if you don't want to save:
Cancel = True

That's it in a nutshell for someone who has done this in a different environment:)

Oh yeah, refer to controls in the class modules of Forms and Reports as
Me.somecontrolname

No need to use .Value since it is the default property and .Text is available ONLY when the control actually has the focus so it is only used in control event procedures such as the on Change procedure.
 

Users who are viewing this thread

Top Bottom