Re: Declaring variables - basic question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Brendan Reynolds" <brenreyn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:u3XAwqePGHA.3408@xxxxxxxxxxxxxxxxxxxxxxx
The latter.

In some languages, including VB.NET, you can declare multiple variables in
this way, specifying the type only once at the end of the line, but in
'classic' VB and VBA you need to specify the type of each variable, or, as
you say, Variant will be used by default.

--
Brendan Reynolds
Access MVP


"Will" <Will5435THISGOES@xxxxxxxxxxx> wrote in message
news:46o23gFc45i9U1@xxxxxxxxxxxxxxxxx
I have found a number of instances in the database I have inherited where
variables have been declared "Dim rs, rh, Dt As Recordset". Does this
mean that rs, rh and Dt are all declared as recordsets or has the previous
programmer misunderstood and rs, rh are actually variants and dt is a
recordset?

Thanks in advance



To the OP:
And if you are going to correct this mistake, you may as well specify the
object library while you're at it. In other words, change:
Dim rs As Recordset
to either
Dim rs As DAO.Recordset
or
Dim rs As ADODB.Recordset

depending on which was intended.


.



Relevant Pages

  • VB6 SQL 2005
    ... Dim cn As Object 'declare connection ... Dim rs As Object 'declare recordset ... Dim strSQL As String 'declare sql command ...
    (comp.lang.basic.visual.misc)
  • Re: ADO to get Access query results
    ... The form is open when I run the query, but from what I now know, ... that makes this a parameter query and I need to specify the parameter ... Dim prc As ADOX.Procedure ... > what happens when you try to open the recordset - is there an error message? ...
    (microsoft.public.data.ado)
  • Re: Syntax error (missing operator)
    ... I take it you got the Type Mismatch error, and then tried various modifications to your SQL statement in an attempt to get past that, resulting in the syntax error. ... Dim db as DAO.Database ... The problem here is that both that library and the "Microsoft DAO 3.6 Object Library" define a Recordset object, but those two object types aren't compatible. ... If you have both references set, and you declare an unqualified Recordset object, Access is liable to make an incorrect assumption about which type of Recordset you are declaring. ...
    (microsoft.public.access.formscoding)
  • Re: is Nothing vs = Empty
    ... Dim irst_Students, irst_ClassPeriods As Recordset ... "Empty" is the value of an uninitialized Variant. ... If you declare them as Variant: ...
    (microsoft.public.access.formscoding)
  • Re: cant delete records!!!!!!!
    ... dim SQL,RefLot ... Set recordset = Server.CreateObject ... 'declare SQL statement that will query the database and execute the ...
    (microsoft.public.vb.database.ado)