473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

'VB in Access' and SQL: Library Management

A question about VB in Access:

Please see the code:

Private Sub collectFromStudent_Click()
On Error GoTo Err_collectFromStudent_Click

Dim accNo As String
Dim queryString As String

accNo = InputBox("Enter accession number of book: ", "Library
Manager")

queryString = "DELETE * FROM studenttransaction WHERE accno= " &
accNo & ";"
DoCmd.RunSQL queryString

Exit_collectFromStudent_Click:
Exit Sub

Err_collectFromStudent_Click:
MsgBox Err.Description
Resume Exit_collectFromStudent_Click
End Sub
This is a event-function which gets activated when a user presses a
button. It accepts a accession number as integer.
Through VB and SQL code how can i determine whether such book with
accession code exists in a table 'studenttransaction' or not?
Whether the DoCmd.RunQSL returns some value?
How to check this?
-Sameer

Nov 13 '05 #1
4 2886
You can do it with the Execute method of either the ADO Connection or the
DAO Database objects ...

Public Sub TestSub()

Dim lngCount As Long
Dim strSQL As String
Dim db As DAO.Database

strSQL = "DELETE * FROM tblTest WHERE TestNum = " & InputBox("TestNum")

If LCase$(Left$(InputBox("Use ADO? (y/n)"), 1)) = "y" Then
CurrentProject.Connection.Execute strSQL, lngCount
MsgBox "Records affected: " & lngCount
Else
Set db = CurrentDb
db.Execute strSQL
MsgBox "Records affected: " & db.RecordsAffected
End If

End Sub

--
Brendan Reynolds (MVP)

"Sameer" <sa******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
A question about VB in Access:

Please see the code:

Private Sub collectFromStudent_Click()
On Error GoTo Err_collectFromStudent_Click

Dim accNo As String
Dim queryString As String

accNo = InputBox("Enter accession number of book: ", "Library
Manager")

queryString = "DELETE * FROM studenttransaction WHERE accno= " &
accNo & ";"
DoCmd.RunSQL queryString

Exit_collectFromStudent_Click:
Exit Sub

Err_collectFromStudent_Click:
MsgBox Err.Description
Resume Exit_collectFromStudent_Click
End Sub
This is a event-function which gets activated when a user presses a
button. It accepts a accession number as integer.
Through VB and SQL code how can i determine whether such book with
accession code exists in a table 'studenttransaction' or not?
Whether the DoCmd.RunQSL returns some value?
How to check this?
-Sameer

Nov 13 '05 #2
It is not clear if you want to know this BEFORE you delete, or after?

Furhter, can there be more then one deletion to happen?

Lets assume just one delete at a time, you could use:

The follwing code would loop utnil the user hits cancel to exit the msgbox
prompt...

Dim accNo As String
Dim queryString As String
Dim rst As dao.Recordset
Do

accNo = InputBox("Enter accession number of book : ", "Library
Manager")

If accNo = "" Then
Exit Do
End If

queryString = "select accno from StudentTransaction" & _
" WHERE accno = " & accNo

Set rst = CurrentDb.OpenRecordset(queryString)

If rst.RecordCount > 0 Then
If MsgBox("Do you want to Delete acc " & accNo, _
vbYesNoCancel + vbQuestion, "Delete?") = vbYes Then
rst.Delete
End If
Else
MsgBox accNo & " not found ", vbExclamation, "not found"
End If

rst.Close
Set rst = Nothing

Loop

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #3
Thanks for help!
When I tried to implement some code it gives an error
'User-defined type not defined' for the statement
Dim db As DAO.Database

Also the DAO.Database class is not available in Object Browser.
May I need to take references like VB?
What I have to do for successful compilation and making this class
available for the coding?
Please help.
-Sameer

Nov 13 '05 #4
The code demonstrates both ADO and DAO methods. If you want to use the ADO
method, you'll need a reference (select References from the Tools menu in
the VBA IDE) to the Microsoft ActiveX Data Objects 2.x Library, while if you
want to use the DAO method you'll need a reference to the Microsoft DAO 3.6
Object Library. From your description, you probably have the ADO reference
already, so if you want to use ADO you could just delete or comment out the
DAO demonstration. You may find the following link helpful ...

http://www.mvps.org/access/bugs/bugs0031.htm

--
Brendan Reynolds (MVP)

"Sameer" <sa******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Thanks for help!
When I tried to implement some code it gives an error
'User-defined type not defined' for the statement
Dim db As DAO.Database

Also the DAO.Database class is not available in Object Browser.
May I need to take references like VB?
What I have to do for successful compilation and making this class
available for the coding?
Please help.
-Sameer

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sameer | last post by:
A question about VB in Access: Please see the code: Private Sub collectFromStudent_Click() On Error GoTo Err_collectFromStudent_Click Dim accNo As String Dim queryString As String
1
by: GSK | last post by:
Hello all, I am trying to migrate my site from In-proc state management to out-of-proc SQL state management. I am having problems with the serialization of my classes. I have added the ...
0
by: Lyle Fairfield | last post by:
SQL Server Management Studio Express CTP is a freely downloadable utility (http://www.microsoft.com/downloads/details.aspx?familyid=82afbd59-57a4- 455e-a2d6-1d4c98d40f6e&displaylang=en) something...
1
by: jeeji | last post by:
HI I am experiencing something funny here where I have two equivalent queries: If I run them through query analyzer, the first runs slower than the second, but if run through C# application, the...
5
by: Jack | last post by:
Hello, I had SQL2000 server running fine on the windows 2003 box. I then installed SQL 2005 Express. They both worked together fine. I then uninstalled SQL 2005 Express and installed SQL 2005...
2
by: RamyaKarthik | last post by:
i have developed the code for library management the code is # include<iostream.h> #include<stdlib.h> #include<fstream.h> #include<string.h> # include<conio.h> class lib { protected:
2
Jimmy Liew
by: Jimmy Liew | last post by:
hi, I found this error message in my Ms SQL Server error log. Does anyone know what is all about? What I should diagnosis on this? The SQL Server management pack script "SQL Server 2000...
0
by: lyle fairfield | last post by:
When I work with MS-SQL Server in Access I keep MSSMSE open at the same time. I use it to do all my work on the SQL database. It has many strengths. One is a search and replace feature in T-SQL....
1
by: nido | last post by:
Please i need the LIBRARY MANAGEMENT SYSTEM You have to design a library management system which will keep record of · All Books · Borrowers
7
by: Lawless | last post by:
The following section, from an sql query, runs perfectly in Microsoft SQL Server Management Studio: the_section=(case when line_no= 101 then 1 when line_no between 102 and 105 then 2 when line_no...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.