473,387 Members | 1,517 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.

Writing records to a table

16
Hi all,

I've got some code to write a record to a table but its got me confused, it works fine but instead of taking the values from the system its giving me popups to fill in the values manually. It should be taking userName, date and time from the system.

Any ideas what I've done wrong,

Here's the code?

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnEngBook_Click()
  2.  
  3. Dim username As String
  4. Dim jID As String
  5. Dim Tvalue As String
  6. Dim LDate As String
  7.  
  8.  
  9. username = Nz(Forms!frmLogin!txtMembername, "")
  10. jID = "job1"
  11. Tvalue = Time
  12. LDate = Date
  13.  
  14. Dim strSQL As String
  15. strSQL = "INSERT INTO tblBooking(userID, jobID, startTime, startDate, bookingStatus) Values([username],[jID],[Tvalue],[LDate],[Active])"
  16. DoCmd.RunSQL (strSQL)
  17.  
  18.  
  19. End Sub
Jan 8 '07 #1
5 2390
willakawill
1,646 1GB
Hi all,

I've got some code to write a record to a table but its got me confused, it works fine but instead of taking the values from the system its giving me popups to fill in the values manually. It should be taking userName, date and time from the system.

Any ideas what I've done wrong,

Here's the code?

Private Sub btnEngBook_Click()

Dim username As String
Dim jID As String
Dim Tvalue As String
Dim LDate As String


username = Nz(Forms!frmLogin!txtMembername, "")
jID = "job1"
Tvalue = Time
LDate = Date

Dim strSQL As String
strSQL = "INSERT INTO tblBooking(userID, jobID, startTime, startDate, bookingStatus) Values([username],[jID],[Tvalue],[LDate],[Active])"
DoCmd.RunSQL (strSQL)


End Sub
Hi. I wonder is this a direct paste of your code? It will not work as is. I don't see what [Active] is supposed to be and I will assume it is another variable not shown in your code:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. strSQL = "INSERT INTO tblBooking(userID, jobID, startTime, startDate,bookingStatus) Values( " _
  3.    & username & "," & jID & ",'" & Tvalue & "','" & LDate & "'," & Active & ")"
  4. DoCmd.RunSQL (strSQL)
Jan 8 '07 #2
JonnyB
16
Hi willakawill,

It is a direct paste of my script and I had missed the active variable from it, I pasted in what you posted which is still bringing up popups to ask for the parameters. Its a job booking sytem and I want the user to be able to just click book and it fill the record in automatically with userID, jobID, startTime, startDate and set jobStatus to active.

I've uploaded it to here so you can take a look http://www.celestepoker.com/Temp/jr_system.mdb . Its got a login script to start with so if you enter username as u1 and password as 00 then click "Create Booking" then "Book" you'll see what i'm tryin to achieve.

Hope you can help.
Jan 8 '07 #3
willakawill
1,646 1GB
Oops. Forgot that this is Access

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. strSQL = "INSERT INTO tblBooking(userID, jobID, startTime, startDate,bookingStatus) Values( " _
  3.    & username & "," & jID & ",#" & Tvalue & "#,#" & LDate & "#," & Active & ")"
  4. DoCmd.RunSQL (strSQL)
make sure that each of these variables contains a value.
Jan 8 '07 #4
JonnyB
16
Cheers for your help,

I got it working perfectly thanks to you.

Here's the solution just incase it'll help any other newbies like me

Expand|Select|Wrap|Line Numbers
  1. Dim username As String
  2. Dim jID As String
  3. Dim Tvalue As String
  4. Dim LDate As String
  5. Dim jobActive As String
  6.  
  7. username = Nz(Forms!frmLogin!txtMembername, "")
  8. jID = "job1"
  9. Tvalue = Time
  10. LDate = Date
  11. jobActive = "Active"
  12.  
  13. Dim strSQL As String
  14. strSQL = "INSERT INTO tblBooking(userID, jobID, startTime, startDate,bookingStatus) Values(  '" & username & "','" & jID & "',#" & Tvalue & "#,#" & LDate & "#,'" & jobActive & "')"
  15. DoCmd.RunSQL (strSQL)
Jan 8 '07 #5
willakawill
1,646 1GB
Cheers for your help,

I got it working perfectly thanks to you.

Here's the solution just incase it'll help any other newbies like me

Dim username As String
Dim jID As String
Dim Tvalue As String
Dim LDate As String
Dim jobActive As String

username = Nz(Forms!frmLogin!txtMembername, "")
jID = "job1"
Tvalue = Time
LDate = Date
jobActive = "Active"

Dim strSQL As String
strSQL = "INSERT INTO tblBooking(userID, jobID, startTime, startDate,bookingStatus) Values( '" & username & "','" & jID & "',#" & Tvalue & "#,#" & LDate & "#,'" & jobActive & "')"
DoCmd.RunSQL (strSQL)
You are very welcome. When you post code here place it within code tags because it makes it easier to read. Just highlight the text that represents your code and click on the # at the top of the submission box
Jan 8 '07 #6

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

Similar topics

3
by: Ian Davies | last post by:
I have the following code which displays some some formatted text in my browser. The problem is I need to create a text file and write the records from this array into it. Does anyone know how to...
0
by: Matt Clepper | last post by:
Ok - debated on posting this on SQL group but here goes... I have a piece of ASP code (function #1) that creates a new SQLTransaction (BeginTransaction) to and begins to write records to the...
13
by: Jeff Pritchard | last post by:
I have an MDB that contains a single table. Checkweigher data is being continuously written to this MDB from a dedicated workstation over a network into the MDB on the server at the rate of about...
6
by: M. Schroeder | last post by:
I use an Access-form to write into an external Oracle table via Oracle-ODBC driver. It is not a read-only connection, and batch autocommit mode set to "all successful statements". I can read...
8
by: Paul | last post by:
I have an application that I am tryign to modify, I never wrote the original so need help with my modifications. Currently the app reads and writes to an Access database with one table 'pupils'...
2
by: darrel | last post by:
Our production web site went down today. We discovered that it was because the XML file we use to create the site navigation (most all of the controls on every page rely on this XML file) was only...
89
by: Skybuck Flying | last post by:
Hello, This morning I had an idea how to write Scalable Software in general. Unfortunately with Delphi 2007 it can't be done because it does not support operating overloading for classes, or...
5
kcdoell
by: kcdoell | last post by:
Good Morning: I am using the following code to add new records to a table that is on my Sub Form. Below is the code that I placed in my Before Update event on my Sub Form: Private Sub...
118
by: Chuck Cheeze | last post by:
This might be in the wrong group, but... Here is an example of my data: entry_id cat_id 1 20 2 25 3 30 4 25 5 35
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.