Originally Posted by
SamT
[FONT=Verdana] is an artifact of VBA Express. The Font tags are hidden inside the code boxes on the page. When you copy text from a code box, it also copies the font tags automatically. Then, when you paste it also pastes the font tags.
If you paste into Notepad first, then copy from Notepad, it will not paste the Font tags. Or you can manually delete them from the VBA Express editor.
Originally Posted by ruby123
Thank you for ur reply...
Can u please explain with a sample code...
Thanks...
Just like you did with "Rows = Rows + 1" except you should use another variable beside "Rows". "Rows" is the iterator variable for the loop, you should only read it inside the loop and never change it.
Hi....
Thanks for your reply...
we are not taking header count....I will explain with the following code,where we used in VBA while uploading sheet into excel...
Here my sheet also an excel....VBA excel is uploading one excel from outside path...
VarSheetA= worksheets("sheet1").Range(strRangeToCheckA)
'Here strRangeToCheckA is the range on the uploaded file/sheet that needs to checked
Set wbkB= Workbooks.open(Filename:=path)
Set varsheetB = wbkB.worksheets(sheetName).Range(strRangeToCheck)
'Determine number of rows in the file being uploaded
rows=Lastrow(wbkB.worksheets(sheetName).Range(strRangeToCheck)
Here I kept one message box for that no of rows being uploaded....
MsgBox " no of rows being uploaded is " & rows-1 'Header row is excluded in the count here....
If( sheetName = "xyz")Then
if (wbkB.Worksheets (sheetName).Range ("A" & rows) =" ") Then
rows=rows-1
End If
EndIf
Coming to my answer is I think rows are adding there ...by rows+1..
The above code is only for uploading no of rows into an excel...
After uploading this rows,it is going to inserting into Database...
That code is mentioned here....I need records count that how many they are inserted into Database...
Dim cmdsqldata As ADODB.Command
Set cmdsqldata =New ADODB.Command
Dim cmdSQLdata1 As ADODB.Command
Set cmdSQLData1=New ADODB.Command
cn1.opem GetDBconnectionString_source
Set cmdsqldata1.Activeconnection=cn1
Iam uploading total two types of excel files using excel Vba.
The uploaded files are inserting to database.
If fileType="xyz" Then
QueryA="select count(Track_ID) as cnt ,max ( p_number)+1 as prn from METADATA_DB.TRACKER_VW where ID = 4"
cmdsqldata1.commandText=queryA
cmdsqlData1.commandType= adCmdText
cmdsqldata1.CommandTimeout=0
Debug.print queryA
Set rs1= cmdsqlData1.Execute()
If rs1("cnt")=0 Then
prn=1
else
Prn=rs1("prn")
End If
Else
If filetype="abc"....then also similar code here...
This is for selecting files and executing insert statements into Database.
If fileType= "xyz" Then
queryA= "select count (version) as cnt,max(version)+1 as ver from SOURCE_DB.table_VW where submission_period=' "
Debug.print queryA
cmdsqldata.commandText=queryA
cmdsqldata.commandType=adCmdText
cmdsqldata.commandTimeout=0
set rs=cmdsqldata.execute()
Here there is for loop to insert all the fileds from the uploaded file...
For x=2 to rows. ex: Range("A" & x)
So x value goes...
queryB= insert into SOURCE_DB... blah blah blah,..,
cmdsqldata.commandtext = queryB
cmdsqldata.commandatype=adcmdatext
cmdsqldata.commandtimeout=0
Debug.Print queryB
Set rs= cmdsqldata.execute()
rows = rows+1
Next x
END IF
set rs= Nothing
-------------------------
public function GetDBConnectString_Source() As String
Const str_connect= "Data source= RST; Database=SOURCE_DB;Persist Security Info= True;Session Mode=ANSI;"
'My connection details to database here...login and password
End Function
My code is there as above now...i need now that no of records are inserted into database..i need records count...
Iam using ADO in my code not DAO....
I think,I will get my records count that are inserted into my SOURCE_DB from queryB
Or Recordset
If iam not wrong ,I can get no of records count from Recordset..am i correct..
If so,my code is here...
Dim recount as integer
Dim recordcount as integer
rscount = rs.RecordCount
MsgBox " No of records inserted is " & rscount
Here I need one messages for...if the no of rows being uploaded or read into excel ( rows-1) is not equal to no of records uploaded into Database...
If rows-1 <> rscount Then
MsgBox " Not all rows were inserted ", vbOKOnly+ vbCritical, " Error"
End If
And I need the missing rows into a separate sheet( new sheet)...
Iam getting error 3704
Run time error 3704: operation is not allowed when the objet is closed.
Thanks...