INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Almost Embarrassed to Ask Insert Questino

Almost Embarrassed to Ask Insert Questino

(OP)
I've been away from Access for years and simple things seem to baffle me.
DoCmd.RunSQL "INSERT INTO tStudents (StudentID) VALUES (StudentID) "

The Student ID is an Integer. As I close the current form I want to insert the StudentID value into the table tStudents Column StudentID

Any help is appreciated

RE: Almost Embarrassed to Ask Insert Questino

Try this:

CODE --> vba

DoCmd.RunSQL "INSERT INTO tStudents (StudentID) VALUES " & Me.StudentID 

Duane
Hook'D on Access
MS Access MVP

RE: Almost Embarrassed to Ask Insert Questino

(OP)
Thanks Duane, It still has an error and the line is highlited. The Me.StudentID has the correct value though. The table I'm working with currently is named tActivities. Once I get it working I will use is other places.

Private Sub Command116_Click()
DoCmd.RunSQL "INSERT INTO tActivities (StudentID) VALUES " & Me.StudentID
DoCmd.Close acForm, "frmAddNewStudent"
End Sub

The Table tActivities has the following:
Field Name StudentID data type is Number (long Integer)
10 other fields with Short Text and Numbers

Thank you

RE: Almost Embarrassed to Ask Insert Questino

(OP)
Run-Time error '3134'
Syntax error on Insert Into Statement.

I'm trying different tables and different fields and the result is the same. But the Me. statement always has the data I'm trying to insert.

RE: Almost Embarrassed to Ask Insert Questino

(OP)
OK, all of a sudden this works - DoCmd.RunSQL "INSERT INTO tActivities (StudentID) VALUES (StudentID)". My StudentID was 7 digits long and I had them formatted as Integer. One of the few things I did was change them to Text.

RE: Almost Embarrassed to Ask Insert Questino

I would be very surprised if this worked:

CODE --> VBA

DoCmd.RunSQL "INSERT INTO tActivities (StudentID) VALUES (StudentID)" 

Duane
Hook'D on Access
MS Access MVP

RE: Almost Embarrassed to Ask Insert Questino

(OP)
I don't know what t say. Here is the code. It is the click event for closing the form. I need to populate the other three tables with only the StudentID. This code does that. If something goes terribly wrong later I will know where to look!

Private Sub Command116_Click()
Dim StudentID As Integer
DoCmd.RunSQL "INSERT INTO tActivities (StudentID) VALUES (StudentID)"
DoCmd.RunSQL "INSERT INTO tEmContact (StudentID) Values (StudentID)"
DoCmd.RunSQL "INSERT INTO tInteractions (StudentID) Values (StudentID)"
DoCmd.Close acForm, "frmAddNewStudent"
End Sub

RE: Almost Embarrassed to Ask Insert Questino

JAES,
You declare StudentID but never assign any value to it.

You may also consider this:

CODE

Private Sub Command116_Click()
Dim StudentID As Integer
Dim strSQL As String

StudentID = ???

strSQL = "INSERT INTO tActivities (StudentID) VALUES (" & StudentID & ")"
DoCmd.RunSQL strSQL

strSQL = "INSERT INTO tEmContact (StudentID) Values (" & StudentID & ")"
DoCmd.RunSQL strSQL

strSQL = "INSERT INTO tInteractions (StudentID) Values (" & StudentID & ")"
DoCmd.RunSQL strSQL

DoCmd.Close acForm, "frmAddNewStudent"
End Sub 

This way you can examine your INSERT statement before is executed.

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Almost Embarrassed to Ask Insert Questino

(OP)
Thanks Duane and Andy. I had changed the value of StudentID to String but didn't change the declare statement. The latest code works great by changing the declare to string. It's amazing how much you lose not doing this for 7 years. Hopefully this will wake up some memory cells! Thank you again.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close