jhai_salvador 48 Junior Poster
  1. (sugestion) Move connection close inside "If delete_confirmation = MsgBoxResult.Yes Then"

  2. After delete, just clear out your textboxes

    txt_pid.Clear
    txt_pname.Clear
    ....

jhai_salvador 48 Junior Poster

This question has been asked and answered several times already. if you try to use the search bar on this forum, you find the answer to your question. you can also use GOOGLE to find answer to your question.

here are some links that could help you.

https://www.daniweb.com/software-development/visual-basic-4-5-6/threads/29709/search-code-in-a-database

https://www.daniweb.com/software-development/visual-basic-4-5-6/threads/334183/how-to-create-a-search-command-in-vb6

https://www.daniweb.com/software-development/visual-basic-4-5-6/threads/445719/how-to-search-database-and-display-matching-record-in-vb6-

jhai_salvador 48 Junior Poster

Is this purely on SQL or it will be use in VB6?

jhai_salvador 48 Junior Poster

How about arrays?

Private Function ReturnArrays(SomeArgs As String) As String()
   'Code goes here
End Function

You can also use user define types and even classes.

jhai_salvador 48 Junior Poster

We already have an improved version, it's VB.net. With improved Intellisense, improved documentation(for the most part), and more developer control, the only reason I use VB6 anymore is to help people still using it.

Im sorry but i wont consider VB.NET as the same as VB6. Anyway I just need votes for it so if you really like the classic Visual basic then please do vote.

Thank you,

jhai_salvador 48 Junior Poster

Follow what tinstaafl said and also start learning to use array objects and variables. I promise you that you're life will be easier on using array objects ;)

OT: I don't know where to post this but i need your support by voting Visual Basic Classic to be improved: Bring back Classic Visual Basic, an improved version of VB6

thanks,

jhai_salvador 48 Junior Poster

heres what you can do:

  1. Open your template form in notepad (form with the extension of .frm) - this is the form you want to copy the menu.
  2. After you open it with notepad, find the Begin VB.Menu and COPY it. Something like this;

    Begin VB.Menu mnuGroups
    Caption = "&Groups"
    Begin VB.Menu submnuGroups
    Caption = "Add Group"
    Index = 1
    End
    Begin VB.Menu submnuGroups
    Caption = "Edit Group"
    Index = 2
    End
    Begin VB.Menu submnuGroups
    Caption = "Delete Group"
    Index = 3
    End
    End

Make sure you copy from Begin VB.Menu up to the End correctly as you can see on the snipped above.

  1. Open the other form in notepad - this is the form where you want to recreate the menu.
  2. Find the Attribute VB_Name and above it, there should be End, now, paste your copied code above that End

it will look something like this after you paste it in the form where you want to recreate the menu;

..
......
   Begin VB.Menu mnuGroups 
      Caption         =   "&Groups"
      Begin VB.Menu submnuGroups 
         Caption         =   "Add Group"
         Index           =   1
      End
      Begin VB.Menu submnuGroups 
         Caption         =   "Edit Group"
         Index           =   2
      End
      Begin VB.Menu submnuGroups 
         Caption         =   "Delete Group"
         Index           =   3
      End
   End
End
Attribute VB_Name = "frmMain"

Thats it.

jhai_salvador 48 Junior Poster

thats a lot of code. why not try http://support.microsoft.com/kb/220595 since he/she is using outlook.

jhai_salvador 48 Junior Poster

have you tried it without using late binding?..

jhai_salvador 48 Junior Poster

just do what ponnu said, you can replace rs.Fields("NAME").Value & ", " & RsFields("AGE").Value with var1 & ", " & var2 etc if your using variables and not database.

jhai_salvador 48 Junior Poster

My pleasure to help you. Please mark the thread as SOLVED.

jhai_salvador 48 Junior Poster

This is what Im using on my crystal report 8.5.

Reports are created and connected via odbc so database location can be easily change.

Dim crxTable As CRAXDRT.DatabaseTable
Dim mReport As CRAXDRT.Report

For Each crxTable In mReport.Database.Tables

 '* Use to Connect via ODBC,
 '* crxTable.SetLogOnInfo(pServerName As String, [pDatabaseName], [pUserID], [pPassword])

 crxTable.SetLogOnInfo "ODBCName", "db.mdb", "admin", "passwordgoeshere"
 DoEvents
Next
jhai_salvador 48 Junior Poster

How about using Property GET/Let?

Put this code in your form (General Declaration Section)

' Variable to hold 'VarValue' property value
Private refVarValue As String

Public Property Get VarValue() As String
   VarValue = refVarValue
End Property

Public Property Let VarValue(ByVal strValue As String)
   refVarValue = EnuValue
End Property

Then, when you call the form where you put the code above (ex, Form1)

Form1.VarValue = "Your String goes here"
Form1.Show

'Then on form1 load event, put this code
Private Sub Form_Load()
   Debug.Print refVarValue
End Sub

Try to run it and see what happens.

jhai_salvador 48 Junior Poster

Heres a sample on how to add a record to database.

Dim rstInfo As New ADODB.Recordset
Dim SQL as String
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
rstInfo.Close
Set rstInfo = Nothing

Happy coding :D

jhai_salvador 48 Junior Poster

If you want your assignment to be done completely then you can post your project at vworker.com. This will cost you but if you really need a complete source then try it! ;)

Post a Project for me Then I will be glad to give you a complete source ;)

jhai_salvador 48 Junior Poster

:D my given samples should work with your needs so you just need to analyze and understand it.

jhai_salvador 48 Junior Poster

Yes, just like my 2nd Post. :D

jhai_salvador 48 Junior Poster

Why not use my err function in the code snippet? so it will be easy to locate the error line.

Make sure that your recordset is closed before you open it again.

if RecSet.State = AdStateOpen Then
RecSet.Close
End If
jhai_salvador 48 Junior Poster

If you don't know much about sql, then try the other way around like storing record from a variable.

Dim UserType as string 

UserType = rs!UserType 
if UserType <> "Admin" Then
   rs.Delete
End If

Heres a code of the delete using sql.

DBLink.Execute "Delete From Users Where ID = " & lvwUser.SelectedItem.Text & " AND UserType = 'Administrator'"
DBLink.Execute "Delete From Users Where ID = " & lvwUser.SelectedItem.Text & " AND UserType = 'User'"
jhai_salvador 48 Junior Poster

How about showing your effort first?

You can check out this code snippet of mine to see how I manipulate the strings.

Here

jhai_salvador 48 Junior Poster

You can use loop then use the Mid function and Iterate through the whole string.

jhai_salvador 48 Junior Poster

Add the first code in line 11 so it will be set to normal. Then the second code will just be before you exit the application or before calling the END keyword that would terminate the application so that it will return in Read Only Mode.

jhai_salvador 48 Junior Poster

:D This is just a trick that might work for # 2. Just follow this steps

1. Right click your Database (*.mdb) > Properties > Tick Read-Only

This will not allow user to make any changes in your database. simple trick right? :D

2. In you VB6 code, use the SetAttr function to set the database to normal (remove read only property)

Use this code to make your database back to normal. Use it before you connect.

Dim DatabaseLocation as String
DatabaseLocation = "D:\SilentProject Softwares\Property and Sales Information\Database\Database.mdb"
Call SetAttr(DatabaseLocation, vbNormal)

Now use this code to make your database as read only. Use it before terminating your application.

Dim DatabaseLocation as String
DatabaseLocation = "D:\SilentProject Softwares\Property and Sales Information\Database\Database.mdb"
Call SetAttr(DatabaseLocation, vbReadOnly)

Hope this solves your problem. :D

jhai_salvador 48 Junior Poster

Your welcome! :D now mark this thread as solve...

jhai_salvador 48 Junior Poster

Just repeat the Replace Function.

Dim A as string, B as string 
A = "@AA@BB@CC@DD@EE@FF@GG@HH@AB"
A = Replace(A, "@BB", vbNullString)
'etc
jhai_salvador 48 Junior Poster

thats easy. Use Replace function.

Dim A as string 
A = Replace("@AA@BB@CC@DD", "@BB", vbNullString)

it will return @AA@CC@DD

Hopes this solves your problem.

jhai_salvador 48 Junior Poster

Haha :D but its a good solution so thats just fine.

jhai_salvador 48 Junior Poster

On Line 22, I think it should be like this.

cbodept.AddItem oRs!Office
jhai_salvador 48 Junior Poster

I did not get that error when I try it myself.

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
   SendKeys "{tab}"
End If
End Sub
jhai_salvador 48 Junior Poster

Hi! Please visit my code snippet thread.

Easy Code Debugging - prompt_err Function

Then add line number in your code like this.

Private Sub cmdPrintSel_Click()
On Error GoTo errHand

1 Call Con("Database.mdb")
2     
3     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
4     
5     Set drtSel.DataSource = RecSet
6     drtSel.Show 1
7     
8 RecSet.Close
9 DBLink.Close


Exit Sub
errHand:
   prompt_err Err, "Form1", "Update_Details"

End Sub

I have use the application that I created to add line numbers with the code (It is also attached in my code snippet).

After that, try running it and you can locate the error more easily. Thanks

jhai_salvador 48 Junior Poster

Try this...

lblids.Caption = lblids.Caption & rs.RecordCount
jhai_salvador 48 Junior Poster

remove this line so you can check if its bug free...

On Error Resume Next

Also add this line on your loop to prevent your application from hanging / lagging..

DoEvents
jhai_salvador 48 Junior Poster

@andre, so doing something like this will make a good practice?

Set rs = New Adodb.Recordset

Set rs = Nothing

rs.open ....

I think not.

Don't get me wrong because I am just giving advice.

jhai_salvador 48 Junior Poster

In your code, you are still using the rs object, but you've destroyed it before it was use using this code.
Set rs = nothing
You must only destroy objects when you are not going to use it anymore.

jhai_salvador 48 Junior Poster

What is the error prompt? What line # did it occur?..

jhai_salvador 48 Junior Poster

Please remove all your "On Error Resume Next" and come back here again.

Make sure all your objects (buttons, textboxes, combo boxes, etc..) exist in the form.

jhai_salvador 48 Junior Poster

First thing is, remove the "On Error resume Next" so you could see error prompts, and then you can come back here and show us the error description.

jhai_salvador 48 Junior Poster

How about visiting my site, you can download my open source project there and learn from it. Thanks

jhai_salvador 48 Junior Poster

Check your listview property like, if Listview propert view is Report style (detailed style) then make sure you have column headers.

ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add "ID"
ListView1.ColumnHeaders.Add "Username"
ListView1.ColumnHeaders.Add "Password"

Above code is just sample, so please try it out. Thanks

jhai_salvador 48 Junior Poster

Google it.. Buy it.. download it..

jhai_salvador 48 Junior Poster

I think i need to correct that code :)

Dim i as Integer
Dim myString as string

For i = 1 to Len(Text1.Text)
 If Mid(Text1.Text,i,1) <> " " then
 myString = myString & Mid(Text1.Text,i,1) '<-- Corrected this one...
 EndIf
Next i
jhai_salvador 48 Junior Poster

@Andre. Thanks.

jhai_salvador 48 Junior Poster

You can use loops

dim i as integer
dim myString as string

for i = 1 to len(text1.text)
 if mid(text1.text,i,1) <> " " then
 myString = myString & mid(text1.text)
 endif
next i

you can do something like that. Thanks

AndreRet commented: Nice alternative. +4
jhai_salvador 48 Junior Poster

Do the following.
1. Add a Timer on the Form
2. Set the Timer Enable, Interval = 1000
3. Add this code

Private Sub Timer1_Timer()
Me.Caption = Format(Now, "s")
End Sub

This code will show you the current time seconds in the form caption or you might want to research on the GetTickCount API function.

jhai_salvador 48 Junior Poster

What report are you using? Is it DataReport? Crystal Report? Active Report?..

jhai_salvador 48 Junior Poster

You want to clear a textbox?..
use this..

Text1.Text = ""
jhai_salvador 48 Junior Poster

its VB.NET and not VB6.. All you have to learn is String Manipulation and their function like Text Replace, Mid, Left, Right...

jhai_salvador 48 Junior Poster

First, When someone solves your problem you must mark it as Solved... Thanks.

Second, in your code, I didn't see where do you want to show the Total for it. Will it be showed in Textbox? in Label?..

Assigning Value in a Textbox Control using Text Property

Text1.Text = readout
or
Text1.Text = subtotal

Assigning Value in a Label Control using Caption Property

Label1.Caption = readout
or
Label1.Caption = subtotal

you can do it something like that...

jhai_salvador 48 Junior Poster

How about showing us what you've done first so we can take a look at it..

jhai_salvador 48 Junior Poster

thanks Jhai u were a great help.
to Abu i had declared A=16%

Your welcome, hope its solves your problem...