Hi there,
I am using INSERT INTO query in order to add records to the access db using VBA. My code is as follows:
rivate Sub cmd_OK_Click()
Dim wrkJet As DAO.Workspace
Dim db As DAO.Database
Dim dbname As String
Dim rs As DAO.Recordset
Dim strSQL As String
Dim Q As DAO.QueryDef
dbname = "C:\Documents and Settings\sanju\Desktop\Project\Commcare.mdb"
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(dbname, , True, "Microsoft.Jet.OLEDB.3.51")
strSQL = "INSERT INTO MasterAccountDetails VALUES (txt_AccName.text, txt_Desc.text, CB_Period.Value, txt_Template.text, txt_Midstarttime.text, txt_Midendtime.text );"
Set Q = db.CreateQueryDef("")
Q.Sql = strSQL
Q.Execute
Q.Close
db.Close
wrkJet.Close
But unfortunately my code generates a run time error stating "Too few parameters.Expected 6.". Presumbly this error msg generates when i don't pass all the required field values. but i have passed all of them. and i cannot understand what is wrong with the statement.
Does anyone know how to solve this prob? Due to some strange reason i can run only SELECT query via VBA. My UPDATE and INSERT query does not seem to be working.
Thanks a lot for u r help in advance.
Sanjna...
I am using INSERT INTO query in order to add records to the access db using VBA. My code is as follows:
rivate Sub cmd_OK_Click()
Dim wrkJet As DAO.Workspace
Dim db As DAO.Database
Dim dbname As String
Dim rs As DAO.Recordset
Dim strSQL As String
Dim Q As DAO.QueryDef
dbname = "C:\Documents and Settings\sanju\Desktop\Project\Commcare.mdb"
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set db = wrkJet.OpenDatabase(dbname, , True, "Microsoft.Jet.OLEDB.3.51")
strSQL = "INSERT INTO MasterAccountDetails VALUES (txt_AccName.text, txt_Desc.text, CB_Period.Value, txt_Template.text, txt_Midstarttime.text, txt_Midendtime.text );"
Set Q = db.CreateQueryDef("")
Q.Sql = strSQL
Q.Execute
Q.Close
db.Close
wrkJet.Close
But unfortunately my code generates a run time error stating "Too few parameters.Expected 6.". Presumbly this error msg generates when i don't pass all the required field values. but i have passed all of them. and i cannot understand what is wrong with the statement.
Does anyone know how to solve this prob? Due to some strange reason i can run only SELECT query via VBA. My UPDATE and INSERT query does not seem to be working.
Thanks a lot for u r help in advance.
Sanjna...