473,385 Members | 1,492 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,385 software developers and data experts.

Saving a form variable to a table

I am trying to create a database that saves marathon times to a database. The way the times are marked are in minutes and seconds. There are 8 sections to the marathon and the times will have to be added together later on (another problem entirely that I will deal with later. :) After researching the best way to do that I found that it is recommended that I convert the minutes to seconds and add the rest of the seconds together and just store the time as an integer. Well I created a form and for time I created two combo boxes, 1 for minutes and 1 for seconds. My plan was to add a button and when that is clicked it will create a new variable(totalTime) and multiply the minutes by 60 and then add the seconds. Now my question is how to get that variable's data into my table? I tried an insert into and it gave me an error. Is the insert into the best route or is there another path I should try?

I feel like I am missing something easy and any nudge in the right direction would be much appreciated.
May 10 '07 #1
5 2337
ADezii
8,834 Expert 8TB
I am trying to create a database that saves marathon times to a database. The way the times are marked are in minutes and seconds. There are 8 sections to the marathon and the times will have to be added together later on (another problem entirely that I will deal with later. :) After researching the best way to do that I found that it is recommended that I convert the minutes to seconds and add the rest of the seconds together and just store the time as an integer. Well I created a form and for time I created two combo boxes, 1 for minutes and 1 for seconds. My plan was to add a button and when that is clicked it will create a new variable(totalTime) and multiply the minutes by 60 and then add the seconds. Now my question is how to get that variable's data into my table? I tried an insert into and it gave me an error. Is the insert into the best route or is there another path I should try?

I feel like I am missing something easy and any nudge in the right direction would be much appreciated.
  1. Post all relevant information such as: Table Structure, Field definitions including Data Types, Names, etc. especially the [Minutes] and [Seconds] Fields.
  2. What's your Form Name, Combo Box Names, etc.
  3. Post the INSERT INTO code that is not working.
  4. How are the Minutes and Seconds data stored? Are there Minutes and Seconds Fields for each section of the Marathon?
  5. I think you got the idea...
May 10 '07 #2
The Race table is BibNum, RaceNum, Time (an integer).

On the form (Form_Race) I have a combo box with the race number (values are stored in row source. Bib Number, a text field.
Time: there is a minutes combo box from 20-180 (stored in row source) and a Seconds Combo box (0-59). These are not tied to a control because I want to use them to calculate a new variable.

This is my code:
Dim totalTime As Integer
totalTime = cboMinutes * 60 + cboSeconds

INSERT INTO Race (BibNum, RaceNum, Time) VALUES ([Form_Race.BibNum],[Form_Race.RaceNum],totalTime)

Error message (Stops on Race) Compile Error: Expected: end of statement
May 10 '07 #3
ADezii
8,834 Expert 8TB
The Race table is BibNum, RaceNum, Time (an integer).

On the form (Form_Race) I have a combo box with the race number (values are stored in row source. Bib Number, a text field.
Time: there is a minutes combo box from 20-180 (stored in row source) and a Seconds Combo box (0-59). These are not tied to a control because I want to use them to calculate a new variable.

This is my code:
Dim totalTime As Integer
totalTime = cboMinutes * 60 + cboSeconds

INSERT INTO Race (BibNum, RaceNum, Time) VALUES ([Form_Race.BibNum],[Form_Race.RaceNum],totalTime)

Error message (Stops on Race) Compile Error: Expected: end of statement
This will do the trick for you.
Expand|Select|Wrap|Line Numbers
  1. Dim totalTime As Integer, strSQL As String
  2. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  3.  
  4. Set MyDB = CurrentDb
  5. Set MyRS = MyDB.OpenRecordset("Race", dbOpenDynaset)
  6.  
  7. totalTime = (Nz(Me![cboMinutes]) * 60) + Nz(Me![cboSeconds])
  8.  
  9. With MyRS
  10.   .AddNew
  11.     ![BibNum] = Me![BibNum]
  12.     ![RaceNum] = Me![RaceNum]
  13.     ![Time] = totalTime
  14.   .Update
  15. End With
  16.  
  17. MyRS.Close
  18.  
  19. Me.Requery
May 11 '07 #4
Thank you so much for trying to help me. I typed in what you wrote and it gave me a new error:
Compile Error: User-defined type not defined

It highlighted the 'Dim MyDB As DAO.Database' part
May 11 '07 #5
ADezii
8,834 Expert 8TB
Thank you so much for trying to help me. I typed in what you wrote and it gave me a new error:
Compile Error: User-defined type not defined

It highlighted the 'Dim MyDB As DAO.Database' part
Your Reference to the Microsoft Data Access Objects is not set. If you are using ADO, then the syntax should be:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As ADODB.Database, MyRS As ADODB.Recordset
May 11 '07 #6

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

Similar topics

2
by: steve | last post by:
Hello, I am trying to import an image file into a form. This would be a persons picture saved in the same directory for every unique record. I don't have any problems making an action button to...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
8
by: AxOn | last post by:
Hi, How can i save the specific RichTextBox in the selected tab if i have several tabs with RichTextBoxes in? The application is a text editor type program and when i try to save the most...
1
by: Magnus | last post by:
I'm testing walkthrough saving data to a Database (Multiple Tables). http://msdn2.microsoft.com/en-us/library/4esb49b4(VS.80).aspx In the famous Customer/Order example, I'm getting referential...
3
by: Andy_Khosravi | last post by:
I'm having a problem with an entry form on one of my applications. It would appear that the save action is sometimes not working, and is generating no error when it fails. I'm hoping one of you may...
13
by: =?Utf-8?B?emlyb3M=?= | last post by:
We have a need, after a user fill out a form, to save that page (aspx) and to send it as attachment by email , and to save it to a database for later retrieval any ideas how to save the aspx...
2
by: paulcis | last post by:
I am trying to produce a dynamic form from a database with unknown amount of records. I need to read the values and create a new textbox for each. I need to create the textboxes at page_init stage...
0
Ajm113
by: Ajm113 | last post by:
Contributing To: Saving RichTextBox from Tab Control Ok, I have a question what would I use if I wanted to do something like a paste function in a Rich Text Box using the code on that thread?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.