Is there a better way of writting This code....

ardy

Registered User.
Local time
Today, 08:36
Joined
Sep 24, 2012
Messages
98
Hello All:
How can I make the following code shorter to use less line of code....

Code:
DoCmd.SetWarnings False
        SQL = "INSERT INTO Guardians (GUSD_Student_ID) VALUES (" & Me.GUSD_Student_ID & ")"
        SQL1 = "INSERT INTO Grades (GUSD_Student_ID) VALUES (" & Me.GUSD_Student_ID & ")"
        SQL2 = "UPDATE Grades SET Grades.Subject = ""BM1(ELA)"""
        SQL3 = "UPDATE Grades SET Grades.Type = ""Exam"""
        SQL4 = "UPDATE Grades SET Grades.Score = ""0"""
        
    Debug.Print SQL, SQL1, SQL2, SQL3, SQL4
    DoCmd.RunSQL SQL
    DoCmd.RunSQL SQL1
    DoCmd.RunSQL SQL2
    DoCmd.RunSQL SQL3
    DoCmd.RunSQL SQL4
    
'Allow user warnings
  DoCmd.SetWarnings True
 
What are you trying to do again? The UPDATE statement will update all records in the grades table. Is that what you intended to do?
 
The SQLs work fine, I just wanted to know is there a way to write the same code but in less number of lines .......for example is there a way to combine all DCmd.RunSQL statements.....
 
This is the best !
Code:
DoCmd.SetWarnings False
SQL = "INSERT INTO Guardians (GUSD_Student_ID) VALUES (" & Me.GUSD_Student_ID & ")"
SQL1 = "INSERT INTO Grades (GUSD_Student_ID) VALUES (" & Me.GUSD_Student_ID & ")"
SQL2 = "UPDATE Grades SET Grades.Subject = 'BM1(ELA)', Grades.Type = 'Exam', Grades.Score = '0'"

Debug.Print SQL, SQL1, SQL2, SQL3, SQL4
DoCmd.RunSQL SQL
DoCmd.RunSQL SQL1
DoCmd.RunSQL SQL2

'Allow user warnings
DoCmd.SetWarnings True
 

Users who are viewing this thread

Back
Top Bottom