|
-
Sep 27th, 2010, 08:04 PM
#1
Thread Starter
Member
OLD SOURCE CODE need Help!!!
this is the code i have and i want to know what it does so i can make a query from it
Code:
Private Sub cmdCheck_Click()
Dim q As QueryDef
Dim rs As Recordset
Dim CountStr As String
Dim Count As Long
If Len(txtFirstName) = 0 Then
MsgBox "Please enter a first name", vbCritical, "LegalSOFT"
Exit Sub
End If
If Len(txtLastName) = 0 Then
MsgBox "Please enter a last name", vbCritical, "LegalSOFT"
Exit Sub
End If
Set q = CurrentDB.QueryDefs("int_qGetCodeCount")
q.Parameters("pCode") = UCase(MakeCode)
Set rs = q.OpenRecordset
If rs.RecordCount = 0 Then
Count = 1
Else
Count = rs("MaxCode") + 1
End If
CountStr = Format(Count, "000")
txtCode = UCase(MakeCode) & CountStr
cmdSave.Enabled = True
End Sub
thanks
-
Sep 28th, 2010, 12:12 AM
#2
Member
Re: OLD SOURCE CODE need Help!!!
Maybe you should've read it and the page you copy and pasted it from?
-
Sep 28th, 2010, 04:38 AM
#3
Re: OLD SOURCE CODE need Help!!!
I'm not familiar with MS Access but it's doing some validation on the first and last name and setting up an update. Do you have a specific question about it?
-
Sep 28th, 2010, 05:12 AM
#4
Re: OLD SOURCE CODE need Help!!!
If Len(txtFirstName) = 0 Then
checks the length of the string (Text) in the textbox named txtFirstName. If it is 0, it means it's empty and it gives the error message and aborts/exits the procedure.
-
Sep 29th, 2010, 01:44 PM
#5
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
i have an already compile version of the software but is using newer code and i just have the original (first) source code.
this is what the software does
we enter "last name" and "fist name"
ex.
"Jackson" "Michael"
the software then makes a code out of it
something like this
JACKMI001
the software looks for a query on the database and if there is another client with the same code (JACKMI001) then it adds a 1 to the counter which ends up like
JACKMI002
the software is suppose to do this but i cant (idk) how to make a query to do this or the software do this.
again thanks for your time and help
-
Sep 29th, 2010, 03:02 PM
#6
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
I'm confused at what your question is... what you just described above seems to be exactly what the code is doing. What exactly is your issue?
-
Oct 1st, 2010, 02:03 PM
#7
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
I dont have the query on my database and i dont khow how to make one that would give me the result the code is asking me for
Thanks
-
Oct 1st, 2010, 02:11 PM
#8
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
Here is some generic code... You would have to know the table name the query is referring too.
vb Code:
Private Sub cmdCheck_Click() Dim q As QueryDef Dim rs As Recordset Dim CountStr As String Dim Count As Long If Len(txtFirstName) = 0 Then MsgBox "Please enter a first name", vbCritical, "LegalSOFT" Exit Sub End If If Len(txtLastName) = 0 Then MsgBox "Please enter a last name", vbCritical, "LegalSOFT" Exit Sub End If 'Assuming that MakeCode is set somewhere else??? rs.Source = ("SELECT MAX(pcode) as ""MaxCode"" FROM [table_name] WHERE pcode = '" + UCase(MakeCode) + "'") rs.Open If rs.RecordCount = 0 Then Count = 1 Else Count = rs!MaxCode + 1 End If rs.close CountStr = Format(Count, "000") txtCode = UCase(MakeCode) & CountStr cmdSave.Enabled = True End Sub
Last edited by Chrissy; Oct 1st, 2010 at 02:17 PM.
-
Oct 1st, 2010, 02:43 PM
#9
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
so by doing this how would the query look like
-
Oct 1st, 2010, 02:50 PM
#10
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
This is the query... Instead of putting it in the database, you can just add it in the code.
Code:
("SELECT MAX(pcode) as ""MaxCode"" FROM [table_name] WHERE pcode = '" + UCase(MakeCode) + "'")
You need to fill the appropriate table name in. I can't be more specific because I don't know what your database looks like. Basically this should return the maximum value of pcode in the database.
-
Oct 1st, 2010, 03:41 PM
#11
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
-
Oct 1st, 2010, 03:52 PM
#12
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
Did you try the code I gave you? The query is in there... you need to replace the [table_name] with the actual name of the table.
-
Oct 1st, 2010, 04:27 PM
#13
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
I tried it already
i removed this part and added yours
Code:
Set q = CurrentDB.QueryDefs("int_qGetCodeCount")
q.Parameters("pCode") = UCase(MakeCode)
Set rs = q.OpenRecordset
-
Oct 1st, 2010, 04:29 PM
#14
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
Are you getting an error? I can't help you if you are not specific...
-
Oct 1st, 2010, 04:36 PM
#15
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
i get an error when i click check
i can print screen the error if u want or stream it
-
Oct 1st, 2010, 04:43 PM
#16
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
this is the error i'm getting
-
Oct 1st, 2010, 04:45 PM
#17
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
compilation error
Could not find the method or data member
the version we have here is in spanish
-
Oct 1st, 2010, 04:48 PM
#18
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
this is the code i have. the table is "tblCustomer"
-
Oct 1st, 2010, 04:56 PM
#19
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
this is what i get on Visual Basic after the compilation error
-
Oct 4th, 2010, 08:50 AM
#20
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
Can you show me the references that are in your project?
-
Oct 4th, 2010, 04:29 PM
#21
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
You also need to set the recordset to the connection... Add this before rs.Source. I don't think it will fix your problem, but you will need it regardless.
vb Code:
Set rs = New Recordset 'Conn is whatever your connection object is defined as. rs.ActiveConnection = Conn
Also you may need to ad a "Group By" clause in the SELECT statement... not sure.
-
Oct 4th, 2010, 07:32 PM
#22
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
which references. database location or what
-
Oct 5th, 2010, 08:14 AM
#23
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
Under Project >> References... which references do you have added to your project. You can just show me a screen shot.
-
Oct 6th, 2010, 04:25 PM
#24
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
here is the reference. Sorry i took long
-
Oct 7th, 2010, 08:33 AM
#25
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
Try selection the Microsoft ActiveX Data Objects Recordset Library too. Then try this for your code.
vb Code:
Private Sub cmdCheck_Click() Dim q As QueryDef Dim rs As ADODB.Recordset Dim CountStr As String Dim Count As Long If Len(txtFirstName) = 0 Then MsgBox "Please enter a first name", vbCritical, "LegalSOFT" Exit Sub End If If Len(txtLastName) = 0 Then MsgBox "Please enter a last name", vbCritical, "LegalSOFT" Exit Sub End If Set rs = New ADODB.Recordset 'Conn is whatever your connection object is defined as... is that CurrentDB? rs.ActiveConnection = Conn rs.Source = ("SELECT MAX(pcode) as ""MaxCode"" FROM tblCustomer WHERE pcode = '" + UCase(MakeCode) + "'") rs.Open If rs.RecordCount = 0 Then Count = 1 Else Count = rs!MaxCode + 1 End If rs.Close CountStr = Format(Count, "000") txtCode = UCase(MakeCode) & CountStr cmdSave.Enabled = True End Sub
-
Oct 11th, 2010, 07:42 PM
#26
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
Thanks for the help but its not working
I added the reference u told me but had no luck and got the compilation error
i think i can make it work if i figure out how to make query on access
i need a query that counts the amount of
code names without the numbers at the end
ex
AGUIAN001
AGUIAN002
AGUIAN003
COUNT ONLY THE AMOUNT OF
AGUIANXXX
-
Oct 12th, 2010, 04:02 AM
#27
Re: OLD SOURCE CODE need Help!!!
MS SQL
select count(*) from YourTable where substring(ColumnName,1,6) = 'Aguian'
-
Oct 12th, 2010, 08:46 AM
#28
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
I don't think you want to use Count(). You are then assuming that all the AGUIAN records are in order starting at one. This would also assume that no records were deleted. I think you should use the MAX() function. This will return the last number used... You are basically creating the primary key for a record correct?
The following SQL statement also assumes that pcode is the name of the field that holds the data you are referencing.
Code:
select MAX(pcode) from tblCustomer where pcode LIKE 'AGUIAN*'
-
Oct 15th, 2010, 03:32 PM
#29
Thread Starter
Member
Re: OLD SOURCE CODE need Help!!!
'Conn is whatever your connection object is defined as.
what would this look like?
like this
rs.ActiveConnection = CurrentDB ??????
-
Oct 15th, 2010, 03:33 PM
#30
Hyperactive Member
Re: OLD SOURCE CODE need Help!!!
I can't see how CurrentDB is defined... is it defined as a Connection? If so, that would be correct.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|