Moving info from an unbound text box to a subform so it will be saved (1 Viewer)

Jazmine88

New member
Local time
Today, 18:26
Joined
Oct 21, 2021
Messages
12
Hi,

I'm hoping someone can help, I am struggling with getting this to work.

Basically I have a form with an unbound text box, in this text box I am putting in results from a test which I want to save so that when the form is opened again the information will still be there. I have tried doing this with a subform since the text box is cleared everytime I close the form. I have tried linking the child and master field so whatever is put in the text box will appear in the subform but it doesn't save it.

I'm hoping someone can help me out with this as I've run out of ideas.

The code I use to put the info into the text box is:

Code:
Private sub Command35_Click()

Me.txtResults.Value = Date & " - " & Me.Combo2 & " - " & me.txtCorrect.Value & vbNewLine & me.txtResults.Value

End Sub

Thanks 🙂
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:26
Joined
Sep 21, 2011
Messages
14,046
Why unbound?, why not bound?
 

Jazmine88

New member
Local time
Today, 18:26
Joined
Oct 21, 2021
Messages
12
Why unbound?, why not bound?
The way I have set up the form is setting up all the controls as unbound and then doing VBA to make them work how I want, there may have been an easier way to do this but I wasn't sure how to manage it.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,463
I am not sure about your user interface. Can you post a screen shot? There may be a cleaner solution.
Why enter a value in the mainform to then save as a record in the subform? Why not enter into the subform to start?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,463
The way I have set up the form is setting up all the controls as unbound and then doing VBA to make them work how I want, there may have been an easier way to do this but I wasn't sure how to manage it.
Using unbound forms for data entry is an advanced concept and usually only needed in extreme cases where it cannot be done bounded. Probably some adjustment to the mainform will make this a trivial problem. Again a screenshot or more explanation of the form will help. By binding the mainform you will probably save yourself a lot of unnecessary work.
 

Jazmine88

New member
Local time
Today, 18:26
Joined
Oct 21, 2021
Messages
12
Thank you for your replies, I have included a screenshot of my form below:

Access Screenshot1.png


Basically, the user selects their Belt grade from the top drop down box and all the associated Korean terms can then be selected in the second drop down box and then they can see the answer in English in the third drop down box. If they guessed it correctly they click on the 'correct' button which will increase by one each time and when they have completed all the terms they click 'save results' and the date, belt grade and number of correct answers will go into the Results text box.

At the moment the results will not stay in the text box or the subform, I want to be able to keep the results there so the user can go back and try and beat their earlier score.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:26
Joined
Feb 19, 2002
Messages
42,971
The way I have set up the form is setting up all the controls as unbound and then doing VBA
Access is a RAD (Rapid Application Development) tool and bound forms is the best feature of Access. If you are not going to use the best feature of Access, you might want to just avoid Access altogether and use a different platform. With a bound form, you don't need any code to manage populating and saving data. That is Access' job. Your job is only validation. You validate the data and if it is invalid or incomplete, you tell Access not to save it. Otherwise, you let Access handle things.

Your picture is too low res for me to make out what it is doing.
 

Jazmine88

New member
Local time
Today, 18:26
Joined
Oct 21, 2021
Messages
12
Access Screenshot1.png


I have attached another screenshot so you can see what the form is doing. I have tried to achieve this with a bound form but it doesn't seem to work for some reason. I might have to start from scratch and try again. I have only been using Access for about a year or so and I think this is the most complicated database I have tried to build lol
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,463
The easiest may be to do an insert query into the results table.
"date, belt grade and number of correct answers will go into the Results text box." Is there a UserID saved or is this database used by one person?
 

Jazmine88

New member
Local time
Today, 18:26
Joined
Oct 21, 2021
Messages
12
Thank you, I will try an insert query. At the moment it is only used by me until I can get it working but then I may see about letting other people have access to it as well so I may eventually add in a UserID.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:26
Joined
May 21, 2018
Messages
8,463
If you want to work directly with the subform, you cannot reference a subform by name. You have to get a reference to the subform through the parent form. Also if you are not already at a new record then you would have to move the subform to a new record or you will overwrite the previous value

Code:
Private sub Command35_Click()
   dim sfrm as access.form
   set sfrm = me.SubformControlName.Form
   if not sfrm.newrecord then sfrm.recordset.addnew
   Sfrm.txtResults =  Me.txtResults.Value = Date & " - " & Me.Combo2 & " - " & me.txtCorrect.Value & vbNewLine & me.txtResults.Value
End Sub

It looks like you are putting results in 1 field. May consider one for the date, one for the belt color, and one for the number correct. That way you can search by date, number correct, and do things like get the avg correct, max correct, date of max correct etc.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:26
Joined
Oct 29, 2018
Messages
21,358
Thank you for your replies, I have included a screenshot of my form below:

View attachment 95679

Basically, the user selects their Belt grade from the top drop down box and all the associated Korean terms can then be selected in the second drop down box and then they can see the answer in English in the third drop down box. If they guessed it correctly they click on the 'correct' button which will increase by one each time and when they have completed all the terms they click 'save results' and the date, belt grade and number of correct answers will go into the Results text box.

At the moment the results will not stay in the text box or the subform, I want to be able to keep the results there so the user can go back and try and beat their earlier score.
Hi. Not sure if this will help at all, but maybe take a look at this previous thread.

Quiz-A-Rama - Who Said Databases are dull | Access World Forums (access-programmers.co.uk)
 

Users who are viewing this thread

Top Bottom