Add Record Issue (1 Viewer)

Jillani

New member
Local time
Yesterday, 21:39
Joined
Jan 27, 2018
Messages
1
Dear friends

anyone help my i want to add record thought add button but when i click on add but its showing error
run time error '3075' :banghead:

Coding...

Private Sub cmdAdd_Click()
'add data to table
CurrentDb.Execute "INSERT INTO student(stdid, stdname, gender, phone, address) " & _
" VALUES(" & Me.txtID & "','" & Me.txtName & "','" & Me.cbcgender & "','" & Me.txtphone & "','" & Me.txtaddress & "')"

'clear form
cmd.clear_click
'refresh data in list on form
frmstudentsub.Form.Requery

End Sub
 

MarkK

bit cruncher
Local time
Yesterday, 21:39
Joined
Mar 17, 2004
Messages
8,180
Another much more robust solution, in which all the delimiters are handled automatically is...
Code:
Private Const [COLOR="teal"]SQL_INSERT[/COLOR] As String = _
[COLOR="DarkRed"]    "INSERT INTO student " & _
        "( stdid, stdname, gender, phone, address ) " & _
    "VALUES " & _
        "( p0, p1, p2, p3, p4 )"[/COLOR]

Private Sub cmdAdd_Click()
[COLOR="Green"]    ' programmatically create temp QueryDef[/COLOR]
    With CurrentDb.CreateQueryDef("", [COLOR="Teal"]SQL_INSERT[/COLOR])
        .Parameters(0) = Me.txtID
        .Parameters(1) = Me.txtName
        .Parameters(2) = Me.cbcgender
        .Parameters(3) = Me.txtphone
        .Parameters(4) = Me.txtaddress
        .Execute dbFailOnError
        .Close
    End With

    cmd.clear_click             [COLOR="green"]' clear form[/COLOR]
    frmstudentsub.Form.Requery  [COLOR="green"]' refresh data in list on form[/COLOR]
End Sub
hth
Mark
 

Mark_

Longboard on the internet
Local time
Yesterday, 21:39
Joined
Sep 12, 2017
Messages
2,111
@OP,

Why are you doing this manually instead of simply having a form that uses your underlying data as the source? Access is pretty good at doing record manipulations, its the reason most use it.
 

Users who are viewing this thread

Top Bottom