The code I provided would solve your problem, no need to use another IF clause there.
Use the code, then your code for saving (NO IF) follows.
The code I provided would solve your problem, no need to use another IF clause there.
Use the code, then your code for saving (NO IF) follows.
Example:
rs.Open "Select * from tablename where criteria = '" & control name & "'", db, adOpenDynamic, adLockOptimistic
If rs.EOF = False Then
MsgBox "Record already exist.", vbExclamation, ""
Exit Sub
End If
rs.Close
'Your code to save new record follows
Much effective if your criteria would be your PRIMARY KEY since there are some records which have the same names etc.
From your prev codes, it seems that you are searching for a current record and modify that specific record with a new value.
If that's the case, the you got to modify your SQL statement.
With rs1
.Open "Select * from due", con, adOpenKeyset, adLockOptimistic
If .Fields("partyname") = " & Me.cmbPartyName & " Then
.Fields("due") = rs1.Fields("due") + Val(Me.txtdue)
.Update 'updates the existing record on your field
'try using a msgbox here to confirm if the old record is updated
Else
.AddNew
!partyname = cmbPartyName
!due = txtdue.Text
.Update
'use a msgbox here to confirm that a new record was created
End If
.Close
End With
`
Note that on the IF clause, there is no .AddNew method since there is already a record, so it'll only update the current.
On the ELSE clause, there is the .AddNew to create a new record and .Update to save it.
Try moving line 29 (End If) before line 33 (End With).
I don't know if you don't receive any compile error on line 2 also, but I do.
Your code on line 28 will also give you an error.
I'm not really sure if what you want to happen is this:
Nothing will happen on single click, only if flexgrid is clicked 2x. If that's what you want, then:
Private Sub Form_Load()
clickSpeed% = GetDoubleClickTime
Timer1.Enabled = False
Timer1.Interval = clickSpeed%
End Sub
Private Sub FlexGrid1_Click()
Timer1.Enabled = True
End Sub
Private Sub FlexGrid1_dblClick()
Timer1.Enabled = False
MsgBox "double click"
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
MsgBox "single click"
End Sub
Edit:
with adodc1
.ConnectionString = connectdb
.RecordSource = "Select * from 'tablename'"
.Refresh
.AddNew
.Recordset.Fields("Tablecolumn name") = txtYourtextbox.Text
'any entry on that specific textbox would be save to that specific column on your table
'make sure your textbox control is connected to your adodc
.Update
end with
The only easy way I can think of this is to put another button with the same Caption as the first one over it.
Try it! :-)
If the datatype in your database is Number, maybe try declaring it as integer in the program.
Dim a as Integer
rs.MoveLast
a = rs.Fields(0)
a = a + 1
Do: 2nd person above me says.
Check if some reference missing, click the item then see description (name of the missing DLL if any)
Otherwise, install SP'c 5 and 6
Try to do what JX said.
Maybe your table login doesn't exist or misspelled.
Or try this:
SQL = "SELECT * FROM [login]"
Oh one more thing, do you have this statement?
Dim SQL as String
Cheerz!!
Here's to give you an idea.
Dim xIdNo As Integer
Dim xEmpID As Integer
xEmpID = rsX!EmpID 'xEmoID var contains the value of your ID column
xEmpID = xEmpID + 1 'Adds 1 to the original value of your xEmpID var
txtIDNo.Text = xEmpID 'Displays it in a textbox
rsX.Close 'Closes recordset
Exit Sub
Much better if you create a Sub for this then call it on your Add button code.
And don't set the textbox to invisible so you can see the effect.
Goodluck
Some links are no longer active.. Cheers!!
Try replacing
con.Open "provider = microsoft.jet.oledb.4.0;persist security info = false; data source = " & App.Path & "\database1.mdb;"
to
con.Open "provider = microsoft.jet.oledb.4.0;data source = " & App.Path & "\database1.mdb; persist security info = false"
Try checking your ADO connection.
I think your missing the connection part.
Here:
'Put this in General Declaration area
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Then have this where you want to create the connection
Set db = New ADODB.Connection
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\Database.mdb"
'Change Database to your database name
Set rs = New ADODB.Recordset
rs.Open "Select DATABASETABLENAME from TABLEFIELD", db, adOpenStatic, adLockOptimistic
'DATABASETABLENAME is the table from your database
'TABLEFIELD is where you records be found
Or you can just do your connection by creating a module.
Public DBLink As New ADODB.Connection
Public RecSet As New ADODB.Recordset
Public Sub Con(Database As String)
DBLink.Provider = "Microsoft Jet 4.0 OLE DB Provider"
DBLink.ConnectionString = "Data Source=" & App.Path & "\" & Database
DBLink.Open
'Still the Database is the database name - rename it to your own
End Sub
Then just call the connection on where you need it.
E.g in a form:
Call Con
What part are you trying to connect your database to?
Is it the project or a datagrid or listview?
If it is your project, the link sir Andre has given will show the basics.
From the code sir Andre given, just remove line 1 and 3.
Don't put the the code in the toolbar.
Place it in your command button (cmdUpdate) in your Modify form.
Try upgrading to VB 6..
On your save button code, put this between line 26 and 28.
frmList.Adodc.Refresh
frmList.DataGrid1.Refresh
Replace your module code with this.
Public CN As New ADODB.connection
Public rs As New ADODB.Recordset
Public Sub CON()
With CN
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & App.Path & "\Database1.mdb"
' so that you dont have to specify the whole drive path of your database
' database should be in the same folder as your app
.Open
.CursorLocation = adUseClient
End With
End Sub
Replace your Save button code with this.
Dim rstInfo As New ADODB.Recordset
Dim SQL As String
Call CON
SQL = "SELECT * FROM List"
rstInfo.Open SQL, CN, adOpenStatic, adLockOptimistic
rstInfo.AddNew
rstInfo!CustomerName = txtName.Text
rstInfo!ContactNumber = txtContact.Text
rstInfo!Date = txtDate.Text
rstInfo!TimeStart = txtStart.Text
rstInfo!TimeEnd = txtEnd.Text
rstInfo!Event = txtEvent.Text
rstInfo!PossibleNumberofGuest = txtGuest.Text
rstInfo!Comment = txtComment.Text
rstInfo.Update
MsgBox "Record has been Saved", vbInformation
rstInfo.Close
CN.Close
Set rstInfo = Nothing
Show us some code or where the error occurs.
Put it in your command button which save the data that is input in your controls.
Usually the saving button ( e.g cmdSave).
You should specify what field of the table what you are trying to get the data from.
Same thing if you are trying to display data from different fields in a control like textbox or labels.
Text1.Text = Rs.Fields("Lname") & " " & Rs.Fields("Fname") & " " & Rs.Fields("Mname")
Fullname = Rs.Fields("Lname") & " " & Rs.Fields("Fname") & " " & Rs.Fields("Mname")
'if Fullname is also a database table field, change it e.g Rs.Fullname
Here's some fixes too.
On form5
on your Adodc1 control
1. Right Click
2. Click Build then on the First textbox where you enter your database path
3. replace the original path with inventory.mdb
4. Click Test COnnection button
5. Ok > Apply
6. RIght click on your Datagrid control then > click Retrieve Fields
And there you go, that message won't be disturbing you again.
Do the same on form 3 (Adodc2)
On form7 cmdAdd
At design time
Set cmbItemName property Style = 2 - Dropdown list
to disable typing on it
Replace your
If cmbItemName.Text = "Select an Item from the list" Then
to
If LenB(cmbItemName.Text) = 0 Then
At design time
Set txtQuantity property Enabled = True so that the Setfocus statement won't give you an error.
Replace your
ElseIf txtQuantity.Text = "0" Then
to
ElseIf LenB(txtQuantity.Text) = 0 Then
Here's an advice:
Practice naming your controls (with correct extensions e.g Command1 to cmdAdd or Text1 to txtName)
This is to make coding easier and avoid being confused
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.?
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. :)
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.
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, …
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!!
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
Can you please clarify if your code is for adding data to database.? (I'm such a noob)
Just like the guy above me said, your code doesn't add data to your database.
Your code really is confusing (alignment thingy), please use tabs.
Try:
If txtsub.Text = rs2.Fields![subjects] then
MsgBox "Please enter StudentID!", vbExclamation, "Error"
txtempno.Text = vbNullString
txtempno.SetFocus
End if
Haven't try this but just think of the concept.
If the textbox value is equal to any record on the database (or what column that is)
then the message appears.
You mean, its not showing any records from your database.?
Hhhmm, i too recieve the error.
Try this:
1. Create a database connection module
Public Dbconn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public Sub createlink()
Dbconn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
Dbconn.Open "EA.mdb"
End Sub
then
2. Replace your code with this:
Dim admissionsql As String 'General Declarations area
Private Sub Form_Load()
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Call createlink
Set db = New ADODB.Connection
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\EA.mdb"
Set rs = New ADODB.Recordset
rs.Open "Select * From Admission", Dbconn, adOpenDynamic, adLockOptimistic
End Sub
This code will show all the records in your database in their respective column.
What line does the error occurs.?
Make sure that all objects seen in your code are present in your form
(e.g DataGrid1).
Please give more information about your problem.
I suggest you use use a full version rather than a portable.
Portables doesn't contain all features of the VB App (Full),
which may be the problem.
Use the full version. Google it
Hhhmm.
I think it has something to do with Timer.
Set its interval and when it reaches the limit,
like in every 3 minutes, it will do the saving function.
I don't know code for that though, you can just google codes for the Timer.
I am noob in networking ^_^
Please mark thread as Solve..
Thanks
Try this.
Private Sub cmdSave_Click()
On Error Resume Next
If txtDate.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtDate.SetFocus: Exit Sub
If cmbTitle.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbTitle.SetFocus: Exit Sub
If txtName.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtName.SetFocus: Exit Sub
If txtIc.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtIc.SetFocus: Exit Sub
If txtEmail.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtEmail.SetFocus: Exit Sub
If txtPhone.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtPhone.SetFocus: Exit Sub
If txtAddress.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtAddress.SetFocus: Exit Sub
If txtAddress1.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtAddress1.SetFocus: Exit Sub
If cmbResidential.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbResidential.SetFocus: Exit Sub
If cmbGender.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbGender.SetFocus: Exit Sub
If cmbNumber.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": cmbNumber.SetFocus: Exit Sub
If txtRental.Text = "" Then MsgBox "Insufficient Data.", vbInformation, "Information": txtRental.SetFocus: Exit Sub
Adodc1.Recordset.AddNew
Adodc1.Recordset!Dateregistration = txtDate.Text
Adodc1.Recordset!Title = cmbTitle.Text
Adodc1.Recordset!Name = txtName.Text
Adodc1.Recordset!Ic = txtIc.Text
Adodc1.Recordset!Email = txtEmail.Text
Adodc1.Recordset!Phonenumber = txtPhone.Text
Adodc1.Recordset!Address = txtAddress.Text
Adodc1.Recordset!Address1 = txtAddress1.Text
Adodc1.Recordset!Residential = cmbResidential.Text
Adodc1.Recordset!Gender = cmbGender.Text
Adodc1.Recordset!Numberofrooms = cmbNumber.Text
Adodc1.Recordset!Rentalprices = txtRental.Text
Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation
End Sub
You can change the message for each entity, such as for txtEmail,
the message can be "Field empty. Please Enter Email address!"
Your welcom brotha.
Please mark thread as solve if your problem was solved.
Start new thread if you have another concern.