If rs.BOF = True Or rs.EOF = True Then
MsgBox "No items available to sell."
Try using
If rs.Recordcount = 0 Then
MsgBox "No items available to sell."
Can you show your modified code.?
If rs.BOF = True Or rs.EOF = True Then
MsgBox "No items available to sell."
Try using
If rs.Recordcount = 0 Then
MsgBox "No items available to sell."
Can you show your modified code.?
@masterfact18
Sorry bro, I'm not familiar with datagrid, i prefer listview.
(Kinda Hijacking my thread)
I only posted that code (still basing on yours) to give you some idea regarding database connection/s.
That code was already posted by me here in the forum too (for some problems), you can at least try to fix your problem and give us some output but we don't do complete projects or those sort of things.
Regarding on your school problem, try to do ADVANCE STUDY and don't just depend on what you learn from school (been there). I think its fair to say that forums are not made for helping (ONLY) but also for STUDYING.
Just like you, I'm a student too.
Peace. :)
If i try to delete an administrator type, the err message appears and yes, it does not delete the record.
But the same happens to a user type account.
And the Operation not allowed when the object is Open
error appears when i click my listview control again to select a record.
Here's my code for the listview:
Con "Database.mdb"
With RecSet
.Open "Select * From Users where ID = " & lvwUser.SelectedItem.Text, DBLink, adOpenKeyset, adLockOptimistic
If .EOF = False Then
txtName.Text = .Fields("UserName")
txtPass.Text = .Fields("PassWord")
txtConfirm.Text = .Fields("PassWord")
cboPriv.Text = .Fields("UserType")
End If
.Close
End With
DBLink.Close
Please mark thread as solved if we help you.
Create another thread if you have further questions.
I believe you already created a thread regarding this topic.
http://www.daniweb.com/forums/thread342079.html
Double posting.
Mark thread as solved. Please don't PM.
Try:
Option Explicit
Dim passattemp As Double
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub cmdLogin_Click()
Dim User As String
Dim CurrentPosition As String
If Text1.Text = "" And Text2.Text = "" Then
MsgBox "Data required, please enter a valid username and password!", vbCritical, "Log-in Error"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
Set db = New ADODB.Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\DATABASENAME.mdb"
Set rs = New ADODB.Recordset
rs.Open "select * from TABLENAME where Username(name of ur field of usernames) = '" & Text1 & "'", db, adOpenStatic, adLockOptimistic
If Not rs.EOF Then
If Text2.Text = rs!Password And Text1.Text = rs!UserName Then
MsgBox "Welcome to The System!", vbInformation, "Log-in Success"
User = Text1.Text
CurrentPosition = rs.Fields("UserType")
' UserType is the Table Field which has values of admin or user
'Depends on your Table Fields - change
With Form3
If rs.Fields("UserType").Value = "Administrator" Then
'all command buttons are set to Enable = True
'your codes here
Else
'all command buttons are set to Enable to False except inventory part and exit
'your codes here
End If
End With
Unload Me
Form3.Show
Else
passattemp = passattemp + 1
If passattemp = 3 Then
MsgBox "You are not an authorized user. Program will close.", vbCritical, "Log In Error"
End
'Err message if the user failed to login with a valid username and pass 3 times
Else
MsgBox "Password incorrect." & vbCrLf & " Attempt left " & 3 - passattemp & "", vbExclamation, …
It does work but it wont delete even the User type accounts.
Plus, i got an error saying Operation not allowed whent the object is Open
Here's the modified code:
Private Sub cmdDelete_Click()
Dim Class As String
Dim intYN
intYN = MsgBox("You are about to delete a record." & vbCrLf & _
"If you click Yes, you won't be able to undo this delete operation." & _
vbCrLf & vbCrLf & _
"Are you sure you want to delete this record?", vbExclamation + vbYesNo, "Confirm Delete")
If intYN = vbNo Then Exit Sub
Con "Database.mdb"
RecSet.Open "Select * From Users", DBLink, adOpenKeyset, adLockOptimistic
Class = RecSet.Fields("UserType").Value
If Class = "Administrator" Then
MsgBox "Operation not allowed. Administrator accounts cannot be deleted.", vbCritical, "Error"
Exit Sub
Else
RecSet.Delete
End If
'DBLink.Execute "Delete From Users Where ID = " & lvwUser.SelectedItem.Text
DBLink.Close
txtName.Text = ""
txtPass.Text = ""
txtConfirm.Text = ""
MsgBox "The Record has been deleted.", vbInformation
Form_Load
End Sub
http://www.daniweb.com/forums/thread341763.html
Regards to that, i also wanted the system not to be able to delete Administrator Accounts
via my code also posted there.
Here's the code again:
Private Sub cmdDelete_Click()
' On Error GoTo err
Dim intYN
intYN = MsgBox("You are about to delete a record." & vbCrLf & _
"If you click Yes, you won't be able to undo this delete operation." & _
vbCrLf & vbCrLf & _
"Are you sure you want to delete this record?", vbExclamation + vbYesNo, "Confirm Delete")
If intYN = vbNo Then Exit Sub
DBLink.Execute "Delete From Users Where ID = " & lvwUser.SelectedItem.Text
DBLink.Close
Call Form_Load
txtName.Text = ""
txtPass.Text = ""
txtConfirm.Text = ""
MsgBox "The Record has been deleted.", vbInformation
Exit Sub
Err:
MsgBox Err.Description, vbCritical
End Sub
My Database field is Users and has 4 fields.
UserType, ID, UserName and Password respectively.
If the user tries to delete an account where the UserType is Administrator, it wont be deleted, else if the UserType is User, it can be.
Sorry, I'm really not good in SQL. :$
For the percentage:
Dim x as Integer ' General Declaration Area
Private Sub cmdPRCNT_Click()
Text1.Text = x * (Val(Text1.Text) / 100)
End Sub
On the On/Off button thingy, use a frame control and put all command buttons on it except the On/Off key.
On design time, set the Frame property Enable to True (its up to you).
On/Off button:
Private Sub OnOff_Click()
Public Operation as Double ' General Declaration Area
Text1.Text = ""
Frame1.Enabled = Not Frame1.Enabled
If Frame1.Enabled Then
Text1.Text = "0"
Operation = 0
Else
Exit Sub
End If
End Sub
Hope this Helps.. :)
WOrking now.
Change line 12 to :
DatabaseLocation = App.Path & "\Database.mdb"
Thanks, really appreciate it.
Try:
Put this on your General Declarations:
Option Explicit
'this part detects if the user press Enter Key
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const KEY_TOGGLED As Integer = &H1
Private Const KEY_PRESSED As Integer = &H1000
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Then on your Login Command button
Dim User As String
Dim CurrentPosition As String
'Sets the database connection
Set db = New ADODB.Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\Database.mdb"
'Change the path to you database drive path or folder location
'Change Database.mdb with your database name w/o removing the ".mdb" extension
'Set the recordset connection on a Table
Set rs = New ADODB.Recordset
rs.Open "select * from TableName where Fieldname = '" & txtPassword & "'", db, adOpenStatic, adLockOptimistic
'Change Tablename to your database table name
'Change Fieldname to your database table field name
'Detects whether the textbox is empty
If LenB(txtPass.Text) = 0 Then
MsgBox "Empty entry. Please provide a valid password.", vbExclamation, "Error"
Exit Sub
End If
If txtPass.Text = rs.Fields("Fieldname").Value Then
'check if the values entered are present on the Password field of the Database table
User = txtPass.Text
CurrentPosition = rs.Fields("Fieldname") 'Change Fieldname
MsgBox "Acces granted.", vbInformation, "Prompt"
rs.Close
db.Close
Unload Me
TeachersZone.Show
Else
MsgBox "Invalid Password.", vbCritical, "Error"
txtPassword.Text = vbNullString
txtPassword.SetFocus
End If
Thanks. The first code works well.
But the second one do not. After i exit the program and view my database property, the Read Only is unchecked.
Here's my code for the program exit.
Private Sub mnuExit_Click()
Dim strMess
If LogOff = False Then
strMess = "You are about to close the Automated Payroll System." & vbCrLf & vbCrLf & "Are you sure?"
If MsgBox(strMess, vbQuestion + vbYesNo, "Exit Confirmation") = vbYes Then
Dim DatabaseLocation as String
DatabaseLocation = App.Path & "\" & Database
Call SetAttr(DatabaseLocation, vbReadOnly)
End
Else
Cancel = 1
End If
ElseIf LogOff = True Then
Unload Me
Form1.Show
End If
End Sub
I ticked the Read Only property before testing your code.
My database connection is via module.
Public cmd As Command
Public DBLink As New ADODB.Connection
Public RecSet As New ADODB.Recordset
Public EnrollFPType As String
Public FPTPath As String
Public Sub Con(Database As String)
DBLink.Provider = "Microsoft Jet 4.0 OLE DB Provider"
DBLink.ConnectionString = "Data Source=" & App.Path & "\" & Database
DBLink.Open ""
End Sub
And i call it in every form that needs that connection.
So how do i add this codes.
What have you done so far, can you show us some codes?
Ok, here's another problem which i really need help.
One suggestion from our panel suggested if we can have a module which do not allow deleting a record (one or more) in the database which are Administrator type.
Those records cannot be deleted whether through
1. the program itself (via code) or
2. directly from the database (w/o setting password for the database file).
Regarding number 2, i really have no idea.
On number 1, here's my code for deleting files:
Private Sub cmdDelete_Click()
' On Error GoTo err
Dim intYN
intYN = MsgBox("You are about to delete a record." & vbCrLf & _
"If you click Yes, you won't be able to undo this delete operation." & _
vbCrLf & vbCrLf & _
"Are you sure you want to delete this record?", vbExclamation + vbYesNo, "Confirm Delete")
If intYN = vbNo Then Exit Sub
DBLink.Execute "Delete From Users Where ID = " & lvwUser.SelectedItem.Text
DBLink.Close
Call Form_Load
txtName.Text = ""
txtPass.Text = ""
txtConfirm.Text = ""
MsgBox "The Record has been deleted.", vbInformation
Exit Sub
Err:
MsgBox Err.Description, vbCritical
End Sub
Thanks.
Great fix sir.. It's working:)
I can't open 2 Word Doc at the same time, it says something about retry or switch.
How would i go around that.
i have to make a log in form that displays a msg if the user uses the username 'letmein'
if not, a msg will also be printed.
But the message to be printed aren't showing.
Here's my code:
<html>
<head>
<?php
if (isset($_POST['submit'])) {
$username = $_POST['username'];
if ($username = 'letmein') {
print ("ACCESS GRANTED. WELCOME!!");
}
else {
print ("INVALID USERNAME. ACCESS DENIED");
}
}
?>
</head>
<body bgcolor="#FFFFFF">
<center>
<form method="POST" action="login.php">
<input type="text" name="username">
<br><br>
<input type="submit" value="Login">
</form>
</center>
</body>
</html>
1. Its only on my laptop sir, not connected to LAN or anything like that
2. Yes, i close the doc first before reopening, and by doing so, the err appears
Yes, they have the same code except the
wrdApp.Documents.Open App.Path & "\Reports\Locatorslip.docx"
I replace the doc name with another corresponding to the report named on the cmd button.
Regarding my earlier post.
http://www.daniweb.com/forums/thread327097.html
I encounter an error saying
Run-time error '462':
The remote server machine does not exist or is unavailable
Haven't notice this error earlier.
Code:
wrdApp.Documents.Open App.Path & "\Reports\Locatorslip.docx"
wrdApp.WindowState = wdWindowStateMaximize
wrdApp.Visible = True
The code works fine. Error only appears if i click the the button again
(or other which also open a word doc.)
What would be the fix?
Thanks
It Works sir.
Just have to add some Declarations and modifications. :)
Thanks.
I cant really have a code for that sir, its my first time to deal with this kind of prob.
I am use in entering values on comboboxes manually, writing values on the property list.
I'll try your code and get back if i have more further question.
How do i populate a combobox with values from a certain field on my database when i click the control?
My combobox control name :cbodept
Dbase table: Offices
and Dbase Table field is: Office
Preferably code. Thanks
but i have lost text and locked property of text box as it is not available on user control. can this text and locked property of text box on user control can be accessed any other way.
Do you mean typing on the textbox is disabled? (I'm confused) :confused:
You can use code if it is the case. Create a command button/s to enable or disable the text control by using the Locked setting.
'On a command button (e.g cmdEnable)
Text1.Locked = False ' Can be set to True if you wish to lock the control
' Locked property can also be set at design time
You can also use the Enabled property (design or run time)
Text1.Enabled = False ' Can be set to True to enable entry of inputs
' Can also be set during design
Yes you can but not if you take the whole project as a whole.
VB6 default font and font size can be set by form. Create a new form and set the font settings first before creating any controls (textbox, labels, etc.)
But you have to do this again and again when you create new form/s.
However, if you forgot to do this after having controls on the form, you can just select all controls on the form one by one (CTRL + RIGHT MOUSE CLICK) then select the Font property.
CHeers!!
You should provide us more details so we can help you with the proper solution.
Thanks. Got it right.
Preferably the 1st code from sir Andre.
The 2nd one's a bit too long. ;)
Uhm now i know, but now that i try to create a data report that does not have any database connection (At All), it says no Datasource or something like that :lol:
Its a plain report only, a slip. no textbox, only labels and lines.
Can you check your listview control columns if it corresponds to the number of your subitems.?
I think it needs 5 columns.
Thanks for the code snippet, my error was in line 6.
A textbox on my Datareport has a different field name than what is supposed to be.
Great.
Try this:
With lsvwed
Set lst = .ListItems.Add(, , (RS!Lastname))
lst.(lsvwed.ListItems.Count).SubItems(1) = RS!Firstname
lst.(lsvwed.ListItems.Count).SubItems(2) = RS!Middlename
lst.(lsvwed.ListItems.Count).SubItems(3) = RS!Address
lst.(lsvwed.ListItems.Count).SubItems(4) = RS!Age
End With
Im getting this error: Arguments are of the wrong type, out of range or are in conflict with another
Here's my code:
rivate Sub cmdPrintSel_Click()
Call Con("Database.mdb")
RecSet.Open "Select Payroll.EM_ID, Payroll.EM_Name, Payroll.EM_Dep, Payroll.Monthly_Rate, Payroll.dDate, Payroll.xBonus, Payroll.xOT, Payroll.GSIS, Payroll.PH, Payroll.InTax, Payroll.Others, Payroll.absences, Payroll.Advances, Payroll.NetPay " & _
"From Payroll where EM_ID =" & lvwInfo.SelectedItem.Text & " Group By Payroll.EM_ID, Payroll.EM_Name, Payroll.EM_Dep, Payroll.Monthly_Rate, Payroll.dDate, Payroll.xBonus, Payroll.xOT, Payroll.GSIS, Payroll.PH, Payroll.InTax, Payroll.Others, Payroll.absences, Payroll.Advances, Payroll.NetPay having Month(dDate)='" & Month(dt1.Value) & "' And Day(dDate)='" & Day(Me.dt1.Value) & "' And Year(dDate)='" & Year(dt1.Value) & "' Order By Payroll.EM_ID;", DBLink, adOpenKeyset, adLockPessimistic
Set drtSel.DataSource = RecSet
drtSel.Show 1
RecSet.Close
DBLink.Close
End Sub
Can u tell me where i am getting the error, might be in my database.
Is it possible to print a report in VB using only Data Environment.
I mean setting the textboxes only to datasource and datafields in the record
I really dont want to use codes (RS, things like that) cause you see, I'm kind of a rushing so i don't have much time to code now.
The report to be printed is selected in listview control or the records to be printed is selected only.
Just want to print directly.
Thanks, really appreciate it.
Can you tell what errors you've encountered.?
Please mark thread as solved if your problem has been answered.
Uhm yes i guess i got that one now.
Next is the restoration of a DB (one which is selected by the use).
My DB Backup name would be January-04-2010.mdb (Because of the date code), if i select this DB and restore it, it would be renamed to Database.mdb so that it will replace the current DB which is on my App's path.
Thanks again..
HHhmmm, it works sir but wont allow me to close the form if i try to cancel the Add operation.
Got a fixed though, have to create a DB Table which contains the Combobox list items and refer to it.
Public Sub Check()
Dim dbX As ADODB.Connection
Set dbX = New ADODB.Connection
dbX.CursorLocation = adUseClient
dbX.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\Database.mdb"
Dim rsX As ADODB.Recordset
Set rsX = New ADODB.Recordset
'If rsX.State = adStateOpen Then rsX.Close
rsX.Open "Select * from Gender", dbX, adOpenStatic, adLockOptimistic
If cboGender.Text <> rsX.Fields("Gender") Then MsgBox "Select from the list.", vbExclamation, "Error": cboGender.SetFocus: Exit Sub
dbX.Close
End Sub
Just call for Check :idea:
On line 20, my bad.
myFile.CopyFile App.Path & "\MyFolderFrom", App.Path & "\MyfolderTO\", True
Replace it to
myFile.CopyFolder App.Path & "\MyFolderFrom", App.Path & "\MyfolderTO\", True
@Sir Andre
Keeping successfully created progs kinda good thing to do :cool:
Menu > Add Module > OK then Write your code/s.
You can use your module by the CALL argument of whatever you have declared in your module.
At the guy above me:
Have a try on this:
Public Dbconn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public Sub DBCon()
Dbconn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
Dbconn.Open "PNP.mdb" 'where PNP.mdb is the Database Access Name
End Sub
You can then just use the connection by Call-ing it
Call DBCon
And please don't hijack others post. Start your own
Hhhmm, setting it to True would disable selecting from the list also..
Having trouble with my code.
You can see the values of the list in the code.
Here's my code:
If cboGender.Text <> "Male" Or "Female" Then MsgBox "Please select from the list provided.", vbExclamation, "Error": cboGender.SetFocus: cboGender.Text = "Male": Exit Sub
If cboGender.Text = vbNullString Then MsgBox "Please select from the list provided.", vbExclamation, "Error": cboGender.SetFocus: cboGender.Text = "Male": Exit Sub
If cboStat.Text <> "Single" Or "Married" Or "Widow" Or "Seperated" Then MsgBox "Please select from the list provided.", vbExclamation, "Error": cboStat.SetFocus: cboStat.Text = "Single": Exit Sub
If cboStat.Text = vbNullString Then MsgBox "Please select from the list provided.", vbExclamation, "Error": cboStat.SetFocus: cboStat.Text = "Single": Exit Sub
The problem is that, even if i enter another value on my combobox except from the list provided, the error doesn't occur. It should only accept values from the list provided and doesn't accept any other values including null values.
I think he/she is referring on creating an EXE file but compiling it first.
If you create an EXE file of your VB Project, VB automatically compiles it and stops if there are any error on your program.
To check for errors more accurately, hit CTRL + F5 rather than just F5 (for testing purposes after each coding).
If this is what you mean that is.
Try:
Private Sub cmdBackup_Click()
call FCopy
End Sub
Public Sub FCopy()
On Error GoTo err:
'myFile - Change if desired
Dim myFile As New FileSystemObject
Set myFile = Nothing
myFile.CopyFile App.Path & "\MyFolderFrom", App.Path & "\MyfolderTO\", True
'App.Path - if the folder you would like to copy is in the same path as your app
'Change according to your app
'MyFolderFrom - Source, can be the path of the folder to be copied
'MyfolderTO - Destination, the path where the folder will be copied to
'True - Condition if it will overwrite a current folder (with the same name)
'can be False
MsgBox "Folder Copy Success.", vbInformation, "Information"
Exit Sub
err:
MsgBox err.Description, vbCritical
End Sub
For modification purposes sir.
Let's say I Backup my database at 9:00, then I had to add a User at 10:00, so rather than replacing the first backup, it would just create another backup file.
So that I can Restore any of the database backup if there is any need of looking at records on earlier date.
Still keeping the Database.mdb (still, if possible).
I would like my login form to display a message when the user logging in
pressed the CAPSLOCK key when he is entering data in the password textbox.
I tried using this code on Keypress Event
If KeyAscii >= 65 And KeyAscii <= 90 Then
txtPass.Locked = True
Msgbox "CAPSLOCK Pressed."
Else
txtPass.Locked = False
End If
but doesn't work when I tried it.
I also see some codes like GetKeyboardState API but I don't really know
how to use that. :$
Thanks in advance.
Code snippet much appreciated.
@UnderSurvival:
HHhhm, that code worked for me. Just don't know if it didn't work for you.
Well, thanks also.
Mark thread as Solved if problem's fixed.
Ok, my code for my Backup module works well via Copyfile.
Here's what it can do (current):
Backup my Database but using the date function as its filename
Restore my backup file only if the filename is Database.mdb
Here's a screenshot of the prog:
http://img262.imageshack.us/i/restore.png/
and the backup files:
http://img152.imageshack.us/i/backups.png/
Note: If I backup my database on the same day, it will just delete the file with the same date.
Heres my code (Backup):
Public Sub DBBackup()
'On Error GoTo err:
Dim myFile As New FileSystemObject
Dim myTrue As String
Dim myTemp As String
If myFile.FolderExists(App.Path & "\Backup") = False Then
myFile.CreateFolder App.Path & "\Backup"
End If
Set myFile = Nothing
myTrue = App.Path & "\Backup\" & Format$(Date, "mmmm-dd-yyyy") & ".mdb"
If myFile.FileExists(myTrue) = True Then
myFile.DeleteFile myTrue, True
End If
myTemp = myTrue & Now - DateValue(Now) & GetTickCount
If myFile.FileExists(myTemp) = True Then
myFile.DeleteFile (myTemp)
End If
myFile.CopyFile App.Path & "\Database.mdb", myTrue, False
MsgBox "Database Backup Process Complete", vbInformation, "Information"
lblCBK.Caption = "Backup process complete."
Form2.Enabled = True
cmdClose.Enabled = True
Exit Sub
err:
MsgBox err.Description, vbCritical
End Sub
Here's what I want the module to do:
At backup, it would rename the file to Database.mdb w/out deleting the file w/ the
same name (if thats possible) or not delete it because of different in time the
backup was created.
It can create a multiple backup a day …
Fixed it.
Removed the () and add a \ on "\Backup" to be "\Backup\" on Line 32
Making me problematic for days just because of symbols, Aaarrghh.
Really don't know why this works but thanks anyway.
Going to start another topic after a minute :)