save button

  • Thread starter enrico via AccessMonster.com
  • Start date
E

enrico via AccessMonster.com

i tried to create a button with no help of a wizard. it worked out well until
the save part, it doesn't save at all. it doesn't show any error either. this
my code behind the button:

If Nz(Me.txtHospital, "") = "" Then
MsgBox "Please enter name of hospital."
Me.txtHospital.SetFocus
Exit Sub
End If
If Nz(Me.cboCategory, "") = "" Then
MsgBox "Please enter category of hospital."
Me.cboCategory.SetFocus
Exit Sub
End If
If Nz(Me.cboClassification, "") = "" Then
MsgBox "Please enter hospital classification."
Me.cboClassification.SetFocus
Exit Sub
Else
sSQL = ("INSERT INTO tblHospital(Hospital, " & _
" Address, " & _
" Category, " & _
" Classification, " & _
" TelNo) " & _
"VALUES ('" & Me.txtHospital & "', " & _
" '" & Me.txtAddress & "', " & _
" '" & Me.cboCategory & "', " & _
" '" & Me.cboClassification & "', " & _
" '" & Me.txtTelNo & "')")
End If

MsgBox "Data saved.", vbInformation

End Sub

what's the problem with it?
 
D

Daniel Pineault

You've created your sql statement, but you never actually execute it!

You'll need to add something like after your sSQL variable to actually run
your statement.

DoCmd.RunSQL sSQL

or

Set db = CurrentDb
db.Execute sSQL, dbFailOnError


check out

http://www.databasejournal.com/feat...5836/Executing-SQL-Statements-in-VBA-Code.htm

for more info on the subject.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
E

enrico via AccessMonster.com

thanks, it worked. but every time i click the button a message will pop-up
that you are about to append a row, is there a way to omit it?
 
E

enrico via AccessMonster.com

sorry, i already solve that problem already. now, how can i go to data entry
again after saving? because the data i save still remains in the textboxes, i
want it to be cleared and ready for entry again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top