sql - How do I update a table with a form in access using VBA or a Macro? -


i doing best build first database, have come against problem cannot find answer to. complete newbie in forum , writing sort of code please gentle.

i trying create new record in table when student's name double clicked inside list box inside form.

list box want take first (studentid) column value = lststudent

combo box want take second (courseid) column value from: cbocourseid

text box want take third (noteid) column value = txtcoursenoteid

the new record being created in desired table , there no incorrect code errors there no values being carried across fields. autonumber being created (attendanceid) other columns blank. here code:

  private sub lststudent_dblclick(cancel integer)      currentdb.execute "insert tblattendance (studentid, courseid, noteid) values ('me.lststudent','me.cbocourseid','me.txtcoursenoteid')"  end sub 

the fields populated, isn't issue. formatting correct target fields , can't think of else in way.

the new record being created in desired table , there no incorrect code errors there no values being carried across fields. autonumber being created (attendanceid) other columns blank.

with insert statement, you're supplying text values 3 fields in new row ...

insert tblattendance (studentid, courseid, noteid) values ('me.lststudent','me.cbocourseid','me.txtcoursenoteid') 

however studentid, courseid, , noteid numeric fields, not accept text values. in situation, there nothing db engine can insert. still new row added (with new autonumber value in attendanceid), other fields empty.

if include dbfailonerror option .execute, access notify problem (error #3464, "data type mismatch in criteria expression") , abort insert --- new row not added ...

currentdb.execute "insert tblattendance (studentid, courseid, noteid) values ('me.lststudent','me.cbocourseid','me.txtcoursenoteid')", dbfailonerror 

use approach similar @harveyfrench suggested, eliminate single quotes values list ...

dim strinsert string strinsert = "insert tblattendance (studentid, courseid, noteid)" & vbcrlf & _     "values (" & me.lststudent.value & "," & me.cbocourseid.value & "," & _     me.txtcoursenoteid.value & ");" debug.print strinsert ' <- view in immediate window; ctl+g take there currentdb.execute strinsert, dbfailonerror 

based on you've told us, suspect work, i'm not sure it's best way reach goal. open dao.recordset , add new row there. or if can use bound form, access automatically take care of storing new row ... without need write code.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -