vb5prgrmr 143 Posting Virtuoso

Call this my own little quirk but I like to check all three indicators when returning a recordset. (I also for readability like to do it long handed.)

If rs.RecordCount <> 0 And Rs.Bof = False And Rs.Eof = False Then
  TxtPosition.Text = rs.Fields("Position").Value
Else
  TxtPosition.Text = vbNullString
End If

Don't know if changing that will work for you but go ahead and give it a try.


Good Luck

vb5prgrmr 143 Posting Virtuoso

This may also happen with a JOIN query in a PARENT/CHILD relationship. For every record in child that matches parent, parent will show a record. If not using a join query see post above.


Good Luck

vb5prgrmr 143 Posting Virtuoso

try this:

Sub xx()
    Dim txt As String
    Dim x As Variant
    Dim i As Long
    txt = "10,11,12,13,14,15,16,17,18,1,2,3,4"
    x = Split(txt, ",")
    For i = 0 To UBound(x): Next i
    MsgBox "There are " & i & " numbers in your text area"
End Sub

Ahhh....

Why not just use ubound+1?

Sub xx()
    Dim txt As String
    Dim x As Variant
    Dim i As Long
    txt = "10,11,12,13,14,15,16,17,18,1,2,3,4"
    x = Split(txt, ",")
    MsgBox "There are " & UBound(x) + 1 & " numbers in your text area"
End Sub

Good Luck

vb5prgrmr 143 Posting Virtuoso

You can't as far as I know but then again you may be able to subclass the control. You can however use a standard textbox control and set its initial text to " / / ", then test for numbers on keypress to make sure user is entering numbers and if user has entered a number then you would replace the first space with what the user has entered. On the other hand you could use the DTPicker(date time picker) control with a custom format if needed and just allow the user to pick the date.


Good Luck

vb5prgrmr 143 Posting Virtuoso

if you are talking UPPER CASE and lower case the look at UCASE and LCASE


Good Luck

vb5prgrmr 143 Posting Virtuoso

So then you are using this as your mask?

MEB.Mask = "##/##/####"

And you have a problem with the way the control displays this in the standard way that people have come to know?

vb5prgrmr 143 Posting Virtuoso

To add items to a list box you use the additem method...

List1.AddItem "MyString"

To make your list box allow multiple selections set its multiselect property to true on/in the property box.

To run through the list to test which one(s) have been selected. Use a for loop...

Dim ForLoopCounter As Integer
For ForLoopCounter = 0 To List1.ListCount - 1
  If List1.Selected(ForLoopCounter) = True Then
    'do something
  End If
Next ForLoopCounter

To remove an item or items from a list box. Once again use a for loop but this time do it backwards...

Dim ForLoopCounter As Integer
For ForLoopCounter = List1.ListCount - 1 To 0 Step -1
  If List1.Selected(ForLoopCounter) = True Then
    List1.RemoveItem ForLoopCounter
  End If
Next ForLoopCounter

use the menu editor to create your menu items and if you don't know how to use it, there are several tutorials out there, just search the web.

Now to enumerate through all the fonts on the system, use a for next loop...

For ForLoopCounter = 0 To Printer.FontCount - 1
  List2.AddItem Printer.Fonts(ForLoopCounter)
Next ForLoopCounter

That should be enough to get you started. If you have any more questions google and yahoo are your friends as is this forum.


Good Luck

vb5prgrmr 143 Posting Virtuoso

Hmmm... I thought we were in the VB Classic forum!!!

Yes, just opening the IDE and creating a program alters the registry of the machine the program was designed on.

Oh, you mean when you install the program? Yes, when you install the program on another machine there will always be registry entries. The more dependancies you have the more entries will be made (unless those dependancies are already on the computer in question).

As for the question that was attempted to be answered by the VC++ answer, well you can read, update, and insert values into the registry with the SaveSettings and GetSettings VB Functions or if you need more control, you can use the following API's

RegCreateKey or RegCreateKeyEx
RegDeleteKey
RegQueryValue or RegQueryValueEx


Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, to get or set controls in other forms it is as simple as...

'we are in form1 and we want the width of label1 in form2
MyVariable = Form2.Label1.Width

or to set...

'we are in form1 and we want to set the width of label1 in form2
Form2.Label1.Width = MyVariable

Good Luck

vb5prgrmr 143 Posting Virtuoso

very vague question, perhaps some code or a further explanation of what you mean.


Good Luck

vb5prgrmr 143 Posting Virtuoso

NO! That is for you to do and for you to learn how to do!

vb5prgrmr 143 Posting Virtuoso

To display version number...

Option Explicit

Private Sub Command1_Click()
MsgBox App.Major & ":" & App.Minor & ":" & App.Revision
End Sub

Good Luck

vb5prgrmr 143 Posting Virtuoso

IsDate anybody???

Good Luck

vb5prgrmr 143 Posting Virtuoso

Last = top 1 desc
highest = max

Good Luck

vb5prgrmr 143 Posting Virtuoso

App.HelpFile = App.Path & "\" & HelpFileName.hpj/chm

Good Luck

vb5prgrmr 143 Posting Virtuoso

DataGrid1.ReBind ???

Good Luck

vb5prgrmr 143 Posting Virtuoso

Yes. At least is sounds like you can if this is a parent child relationship, meaning that table2 contains the foreign key from table1's unique ID field, or for some reason you are using two tables to contain unique information.

Look up INNER JOIN.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, these last posts have made me thought that you are unsure of what I am trying to say.

The select top 1 * means give me everything, each column from tablename. Then the order by field name is meant to be ordered by autonumber field. Then desc part means descending so you auto number field is numbered 1,2,3,4,5 and by order that field descending its order is 5,4,3,2,1 and with the select top 1 you get the record with the autonumber of 5 and thus you get the last record entered.

Now the max query even further above says for this field (your roll field) give me the largest number. So if in this column/field you had the values 1,5,3,2,5,4,3,2,1 then it would return the value of the 5.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Ya, know... I found a web site once that had a lot of information on this subject but now I can't find it.... Can't remember the name or search terms I used to find it....

Oh well.... See microsoft...

http://search.microsoft.com/results.aspx?form=MSHOME&mkt=en-US&setlang=en-US&q=speech+sdk


Good Luck

Roebuc commented: Thanks! +2
vb5prgrmr 143 Posting Virtuoso

It is possible but the results that you will get will not be in an easily readable format. Some decompilers break the code of an exe down to assembly, or C. While some say they break it down to VB code, you will not get the original code. What you will get is subs and functions with unintelligable names right along with all variables.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Here are a couple of ways and by no means are these the only ways...

Option Explicit

Private Sub Form_Load()
Dim M As Integer, D As Integer, Y As Integer
Dim S As String, LastDay As Date

M = Month(Now)
D = Day(Now)
Y = Year(Now)

If IsDate(M & "/" & 28 & "/" & Y) = True Then D = 28
If IsDate(M & "/" & 29 & "/" & Y) = True Then D = 29
If IsDate(M & "/" & 30 & "/" & Y) = True Then D = 30
If IsDate(M & "/" & 41 & "/" & Y) = True Then D = 31

LastDay = M & "/" & D & "/" & Y
S = "The last day of this month is " & Format(LastDay, "dddd") & " "

MsgBox S & LastDay

'or
LastDay = M & "/" & 1 & "/" & Y
LastDay = DateAdd("m", 1, LastDay)
LastDay = DateAdd("d", -1, LastDay)

S = "The last day of this month is " & Format(LastDay, "dddd") & " "
MsgBox S & LastDay
End Sub

Good Luck

vb5prgrmr 143 Posting Virtuoso

Yes

vb5prgrmr 143 Posting Virtuoso

That query is not for showing the last roll, it was showing the max value roll. If you want the last roll then...

SELECT TOP 1 * FROM tablename ORDER BY field DESC

Good Luck

vb5prgrmr 143 Posting Virtuoso

FileCopy "Path File Name Of Source File", "Path File Name Of Destination File"


Good Luck

vb5prgrmr 143 Posting Virtuoso

So, Object variable not set...

Use the data form wizard to recreate the ADODC and grid you want. Then take that and place on your form.

Good Luck

vb5prgrmr 143 Posting Virtuoso

This is because of one of the quirks of ADO. -1 means that it has found records but does/did not get an accurate count. A couple of ways to get the accurate count and to test to see if you have records are as follows...

If adoRs.RecordCount <> 0 And adoRs.BOF = False And adoRs.EOF = False Then
  'then we have records
  adoRs.MoveLast
  MyRecordCount  = adoRs.RecordCount
  aodRs.MoveFirst
  '....
Else
  '...
End If

or you can explicitly get the count of records through a count query...

strSQL = "SELECT COUNT(*) AS THECOUNT FROM tablename 'where...
'execute...
MyCount = adoRs.Fields("THECOUNT")

Good Luck

vb5prgrmr 143 Posting Virtuoso

Set gridCounter.DataSource = dataCounter?

Where is it defined?

Set gridCounter.DataSource = rsMyRs

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, what that error is telling you is that you have a unique field ID or otherwise and you are trying to add a duplicate entry. So the question arises. Are you trying to add a duplicate entry or update an ID field? Perhaps a look at your table structure might help because if you have a field that is supposed to be a foreign key but you have it constricted with a unique constraint then that may be your problem.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, don't need to change field name (sorry forgot how you had your tables designed), just change Table1 to Table2 and you will have you count of how many records in Table2 = whatever class name. Then on your roll field when you do your addnew you would use THECOUNT + 1, or you could use a different query if you wanted.

S = "SELECT MAX(roll) AS THEMAX FROM Table2 WHERE class = '" classname & "'"

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, the part you tried to highlight in red is constantly returning zero and it should be something like...

... = Combo1.ListIndex

That is, if what you need is the index number but if your field is 1 based and not zero based like the combo then you will need to do

... = (Combo1.ListIndex + 1)

However, if you are wanting to retrieve the text listed/selected in the combo box then you need...

... = Combo1.Text

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, this was the query I was pointing you too earlier...

S = "SELECT COUNT(*) AS THECOUNT FROM Table1 WHERE class = '" & Trim(Text1.Text) & "'"

You just need to adjust which table it points to (table1 vs. table2) and which field it points to.

Good Luck

vb5prgrmr 143 Posting Virtuoso
varname = Replace(varname, "'", "''")

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, this looks like it may help...

http://vbnet.mvps.org/index.html?code/comctl/lvledger.htm

Good Luck

vb5prgrmr 143 Posting Virtuoso

Simple way is to add a module and declare the public variables there.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Now, I know that does not solve your problem but you have the hints in the add new button on how to find out how many students are enrolled. If you need any more help just ask.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, looking at project now and I have some suggestions...

Under the add new button you should add a check to see if there is information to add...

You should also check to see if the class exists...

Private Sub cmdaddnew_Click()

On Error GoTo cmdaddnew_ClickError

Dim daoRs00 As DAO.Recordset, S As String

If Trim(Text1.Text) = "" Then
  MsgBox "Please Add Class Name", vbOKOnly + vbInformation, "Class Name"
  Text1.SetFocus
  Exit Sub
Else
  S = "SELECT COUNT(*) AS THECOUNT FROM Table1 WHERE class = '" & Text1.Text & "'"
  Set daoRs00 = db.OpenRecordset(S, dbOpenDynaset, dbConsistent, dbOptimistic)
  If daoRs00.RecordCount <> 0 And daoRs00.EOF = False And daoRs00.BOF = False Then
    
    'have a resultset
    If daoRs00.Fields("THECOUNT") > 0 Then
      
      'okay, if count is greater than zero then class already exists
      MsgBox "Class exists!", vbOKOnly + vbInformation, "Duplicate record"
      
      'close rs, exit
      daoRs00.Close
      Set daoRs00 = Nothing
      Exit Sub
      
    Else
      
      rs.AddNew
      rs("class") = Text1.Text
      rs.Update
      
    End If
    
  Else
    
    'if we are here for some reason then the query failed for some reason
    daoRs00.Close
    Set daoRs00 = Nothing
    
  End If
  
End If

Exit Sub
cmdaddnew_ClickError:

MsgBox "cmdaddnew_Click " & Err.Number & ":" & Err.Description

End Sub

Then when the form unloads, you need to take care of your objects...

Private Sub Form_Unload(Cancel As Integer)

On Error GoTo Form_UnloadError

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

Exit Sub
Form_UnloadError:

MsgBox "Form_Unload " & Err.Number & ":" & Err.Description

End Sub

Oh yeah, as you can see in the code examples, …

vb5prgrmr 143 Posting Virtuoso
DTPicker1.Format = dtpCustom
DTPicker1.CustomFormat = "hh:mm:ss tt"
DTPicker1.Value = "10:55:23 AM"

Good Luck

limesight18 commented: thx +1
vb5prgrmr 143 Posting Virtuoso

By roll, I take it you mean enrolled in such class whatever number it may be...

So, you have a TableOfClasses table and a StudentsTable table and you want to know how many students have been enrolled in whatever class. So lets add another table, TableEnrollment.

The fields of this table will be (in very simplistic terms)...

ForeignKeyToClassesTable
ForeignKeyToStudentsTable

Then with this information we can then do a simple count query against the EnrollmentTable...

strSQL = "SELECT COUNT(*) AS THECOUNT FROM tblEnrollment WHERE ForeignKeyToClassesTable = " & 10 'class # 10
....
CountOfStudents = adoRs.Fields("THECOUNT") 'this ='s the number of students already enrolled. Then if we did a +1 we would have the count of how many students are enrolled in this class now that we added this student.

Now that is only one way to accomplish this and depending upon your table structure we may be able figure out a different way of accomplishing what you need.

Good Luck

vb5prgrmr 143 Posting Virtuoso

A single project can contain up to 32,000 "identifiers" (any nonreserved keyword), which include, but are not limited to, forms, controls, modules, variables, constants, procedures, functions, and objects. Note that the actual number of identifiers is limited to available memory.

Good Luck

vb5prgrmr 143 Posting Virtuoso

remove the date part of my suggestion...

Good Luck

vb5prgrmr 143 Posting Virtuoso

from vb's help file...

Project Limitations


A single project can contain up to 32,000 "identifiers" (any nonreserved keyword), which include, but are not limited to, forms, controls, modules, variables, constants, procedures, functions, and objects. Note that the actual number of identifiers is limited to available memory.

Variable names in Visual Basic can be no longer than 255 characters, and the names of forms, controls, modules, and classes cannot be longer than 40 characters. Visual Basic imposes no limit on the actual number of distinct objects in a project.

So I don't think you should be worried yet...

However, I would suggest that you break up your code some and perhaps move some of your forms code to modules.

Good Luck

vb5prgrmr 143 Posting Virtuoso

I believe this should get you started...

DTPicker1.Format = dtpCustom
DTPicker1.CustomFormat = "MM/dd/yyyy hh:mm:ss tt"

Good Luck

vb5prgrmr 143 Posting Virtuoso

Well, it really depends on exactly what you are doing...

If you have something like this...

Procedure01 calls procedure02
Procedure02 calls procedure03
03 calls 04
04 calls 05
....

Then what you are doing is building up the stack space and thus you can see the memory expand.

However if you do something like this...

01 calls 02 and 02 returns to 01 (then pop off the stack it comes)
01 calls 03 and ....

then your memory will fluxuate up and down but not too seriously unless you keep building things up in memory... Meaning if you have lets say a string varible declared in the general declaration section of the form and your sub/functions keep adding to it.

So when you say your private variables are not being cleared when a sub is done, it leads me to belive that these variables are in the general declaration section.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Wrong forum, you need the dot net forum...

vb5prgrmr 143 Posting Virtuoso

Then you should be able to use the click event of the combo box to query for the ID be it against the database, the text of the combo box (if you saved the ID with the text) or against its index (if you have some sort of way of doing that.

Good Luck

vb5prgrmr 143 Posting Virtuoso

Okay, several options here that I can think of but without further code I'm shooting in the dark but here is what I can guess from what I have read so far...

You have a table with sales reps names that has a unique ID.
The combo is populated with the sales reps names as pulled from database by some order but probably on the unique ID.

Problem at this point. While the unique ID is more than likely 1 based the combo box index is 0 based and if you could guarantee that reps would always never quit, retire, or die then all you would need is unique ID - 1 to get the sales rep name to display and inversly Index + 1 to set the sales rep. However, I doubt that you could gaurantee such a thing.

So now you want to display in the combo box the name of the rep that will be credited for the sale and you have the reps unique ID in the .SalesRep variable.

So, with this information you can...

Query the database for the reps name, then loop through the combo box looking for a match and once the match is found then use the index to display the name.

OR

You could create a type something like...

Private Type Rep
  RepName As String
  RepIndex As Integer
  RepUnique As Long
End Type
Dim Reps() as Rep

and when you populate the …

vb5prgrmr 143 Posting Virtuoso

So you say it runs on your computer but not on another. Did you create an install package with the Package and Deployment Wizard (A.K.A. PDW) or use Inno to do so and if you did then did you install in on the other computer?

vb5prgrmr 143 Posting Virtuoso

Where is .SalesRep declared and where is its parents with statement?

Good Luck

vb5prgrmr 143 Posting Virtuoso

But this is what I am getting at right here from your first post...

Private Sub Command3_Click()
>>>Set CON = New ADODB.Connection
>>>If CON.state = adStateOpen Then

At this point you have not opened the connection object. You have only declared it and in your next line you test before it is open. That is what I was getting at.

Good Luck

vb5prgrmr 143 Posting Virtuoso

If you are talking about where you have the color tags that show up as text then I would say you have to open the connection before you can test it. From what I see you have only declared the variable con as a New ADODB.Connection but have not acutally opened it.

Basically you have done something like this...

Dim I as Integer
If I = 2 Then 'where I will only equal zero because you have not yet given it a value

Good Luck