473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to set a value into a field in a table underlying a form

204 128KB
This one looks simple enough, but I've been struggling with it all day and just can't get it ...

I have a form in which the user can select a record from an underlying table, by using combo box with the wizard's "Find a record on my form based on the value ...". It generates the SearchForRecord macro and locates the required record OK. So far so good.

Now all I want to do is set the value of a Yes/No field in that record to Yes. I have a command button (but have tried toggle button and text box controls) which should set the field then close the form and open a report. The close form and open report work OK, but how to set the field value?

Peter
Jan 30 '17 #1
14 986
PhilOfWalton
1,430 Expert 1GB
Assuming there is a Yes/No field in the underlying table, bind it to a check box (tick).

Then run your code either OnClick which will close the form & open your report, or more likely on the AfterUpdate having checked that the result is True.

Phil
Jan 30 '17 #2
Petrol
204 128KB
This gives me the same result as the toggle button - "Update or CancelUpdate without AddNew or Edit". I tried putting Walks.Edit BeforeUpdate and Walks.Update AfterUpdate, but I don't really know how or where to put them to make it work.
Jan 30 '17 #3
Petrol
204 128KB
For aesthetic reasons I would prefer to use something that looks like a button that matches the other pop-up forms in the series - Make your selection the press Go".
[IMG]C:\Users\Peter\Pictures\Picture1.png[/IMG]
Jan 30 '17 #4
Petrol
204 128KB
oops - I thought that would upload the screenshot!
Jan 30 '17 #5
Petrol
204 128KB
Here is the screenshot (I hope). I would like the green "Go" to trigger the action - store the Yes/No field, close the form and open the report. That's what happens in several other forms in this series.Picture1.jpg
Jan 30 '17 #6
PhilOfWalton
1,430 Expert 1GB
It would appear from yours screenshot that you are trying to select men or women from your tables. This seems to contradict your original post of "select a record" - singular.

Have you a field for sex?
Is the report supposed to all the male participants or all the female participants?

Ca't really help unless both of us are sure what is wanted, and I certainly am not

Phil
Jan 30 '17 #7
Petrol
204 128KB
No, the "Walks" are not physical walks at all, they are spiritual retreats and some are for men only and some are for women only. The combo box selects and offers a choice between the next men's walk and the next women's walk - i.e. the user just has a choice between two, and by the time we get to the Go button it's only necessary to set the yes/no field for the one chosen.
So posting the picture was perhaps misleading. I considered changing the text in the form for the purpose of the illustration to "Would you like the list for Group A or Group B?", and obviously should have done so. But the requirement expressed in the OP was correct.
Jan 30 '17 #8
PhilOfWalton
1,430 Expert 1GB
Ah, Petrol. I asked 2 questions. Don't really think you have answered either

Phil
Jan 30 '17 #9
Petrol
204 128KB
Yes, I have a field for sex. It is the sex of the entire Walk (i.e. of all the people on it, as per my previous post). As stated in the OP, the combo box correctly selects the right one.

Yes, the report is supposed to be all the male participants. But once the correct Walk record is selected, it points to a Walk Participation table which shows the right people.

All I really need is a way to set the yes/no field of the chosen Walk record. Everything else works fine!
Jan 30 '17 #10
Petrol
204 128KB
The Walks table contains the following fields:
WalkNumber (short text, because it's alphanumeric as previously described)
Selected (the Yes/No field I'm trying to set in this form)
Gender (M/F)
StartDate (Date)
Venue (pointer to Venues table)
... (other stuff, irrelevant for present purposes)

The combo box uses a select query to offer a choice between two of these, and searches for and finds the correct record in the Walks table. All I need to do then is set it's "Selected" flag. I successfully close the form and generate the report after that (by code in the AfterUpdate event of the Go button), but at present because the Selected flag isn't set it generates a report for the wrong Walk!
Jan 30 '17 #11
PhilOfWalton
1,430 Expert 1GB
So the Combo Box is ether going going to give "M" or "F"

Let's assume that the combo box is called CboWalks

On Click event of you "Go" button try

Expand|Select|Wrap|Line Numbers
  1. Dim MyDb as Database
  2. Dim WalkSet as RecordSet
  3. Dim SQLStg as String"
  4.  
  5. SQLStg = "SELECT TblWalks.* FROM TblWalks;"
  6.  
  7. Set MyDb = CurrentDb
  8. Set WalksSet = Mydb.OpenRecordset(SQLStg)
  9. With WalkSet
  10.     Do until .EOF
  11.         .Edit
  12.         If !Sex = CboWalks then
  13.             !Selected = True
  14.         Else
  15.             !Selected = False
  16.         End If
  17.         .Update
  18.         .MoveNext
  19.      Loop
  20.      .Close
  21.      Set WalkSet = Nothing
  22. End With
  23.  
Phil
Jan 31 '17 #12
Petrol
204 128KB
Thanks, Phil. I really appreciate your commitment to help me and others like me. I have learned heaps from your posts over the past few months.

But in all our discussion here we seem to have moved away from the original request. Your code looks great and uses things I didn't know about (e.g. ".Edit") but it seems rather more complex than I need. I think you are searching through the entire Walks table. Let me go back to my original post:
"I have a form in which the user can select a record from an underlying table, by using combo box with the wizard's "Find a record on my form based on the value ...". It generates the SearchForRecord macro and locates the required record OK. So far so good.
"Now all I want to do is set the value of a Yes/No field in that record to Yes. I have a command button (but have tried toggle button and text box controls) which should set the field then close the form and open a report. The close form and open report work OK, but how to set the field value?"
And from my last post (#11),
"The combo box uses a select query to offer a choice between two of these, and searches for and finds the correct record in the Walks table. All I need to do then is set it's "Selected" flag. I successfully close the form and generate the report after that (by code in the AfterUpdate event of the Go button), but at present because the Selected flag isn't set it generates a report for the wrong Walk!"

Can we simplify your code to simply set the Selected flag on the record I have already selected?
Jan 31 '17 #13
PhilOfWalton
1,430 Expert 1GB
Sorry, Petrol

I've given it my best shot, but without actually seeing the database, I can't get to grips with what you want.

Hopefully others can help

Phil
Jan 31 '17 #14
Petrol
204 128KB
OK ... thanks very much for your best shot, Phil! I hope someone can see what I'm trying to achieve. Things always look simpler to the person doing it!
Jan 31 '17 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: WindAndWaves | last post by:
Hi Gurus In my quest in putting my first javascript together, I am now trying to conquer something that seems trivial, but has taken me hours. I would like to format a field in a form once the...
1
by: james00_c | last post by:
Greetings- I need to pass multiple email addresses to a "sendto" hidden field in a form. I need to do that because "CC" and "BCC" are not an option. One address webmaster@xyz.com would be...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
1
by: S. van Beek | last post by:
Dear reader, I can change the caption content of a field in a Form with the following VBA code: Rst!<FieldName>.Caption = "<NewCaptionContent>" But if I do the same in a Table the...
4
by: yanjie.ma | last post by:
Hi, I've got a two part question on table and form design (sorry for the length but it takes a bit to explain). Our sales department uses a look-up table to help the them select the best...
13
by: abcdefghijklmnop | last post by:
I have a "Questions" form that reads off of a table and contains a multi-value field called "Keywords". I already know that having a multi-value field is a horrible idea, however, I am patching up a...
3
by: John | last post by:
I have a 2 field table. Field 1 is Category (unique) and field 2 is FilenameToOpen. In code I would like to search for a value in the field Category. When the record is found I would like to pull...
1
by: Ste | last post by:
Hi, I would like to have current date automatically enter into a form that is based on a table, so that from report I can tell how many records I have entered for the day. If I use date() on...
15
by: amy1 | last post by:
Hello everyone, I'm new here and new to Access2007 as well! I have a multi-value field in a form, and would like to calculate the total of the selected values in this field and place the...
2
by: latifju | last post by:
I am new in access. Now I am using MS Access 2010. Problem: I have table named customer with 6fields as follow 1. ID 2. Name 3. Received 4. Paid 5. Balance 6. Date
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.