Please help with VB5 application and Access 97 database 
Author Message
 Please help with VB5 application and Access 97 database

I am a newbie to VB.  I am trying to manipulate an Access database
through a VB5 application.  I have a few questions and would appreciate
any help I could get.

Here is a little bit of background on the database.  The file is called
collections.mdb and consists of 3 fields.  Those being Title, Poster,
and Video.  The Title field is the index field.  I have default values
of "OS" being placed in the Poster field and "VHS" being placed in the
Video field.  I have the Validation text and Validation rule completed
only to allow an acceptable value.

Here is a little bit of background on the application.  I am linking to
the database with a data control which I named datList.  I have my own
buttons on the form for ADD, DELETE, FIND, FORWARD,  PRINT and BACKWARD
because I do not like the data control and I am making that invisible to

the user.

1) How can I get the form to show the total number of records upon
startup?  I am using a label control to display the recordcount but I
cannot get it to show the total until I hit the FORWARD button which I
placed on the form.  I have the following code in the FORWARD button
click_event procedure....
lblCount.caption = datList.recordset.recordcount.   When I put this code

in the form_load event procedure I get an error that about something not

being set.  I do not now how to use a set command.

2) How do I show the current record number on the form at startup and
also when I move FORWARD or BACKWARD through the records.  I cannot find

a method for recordnumber.

3) How do I print the database?  I want the name of the database at the
top of the page and the 3 fields listed below that, and then I want all
the records to be printed.  Basically I want my PRINT button to do the
same thing that happens when I select print from the FILE menu in Access

and it prints the database.  I have placed a CommonDialog control on the

form and named it dlgCommon.  I would like the print setup dialog box to

appear first.  I entered the code dlgCommon.showprinter and that did
that but I do not know the coding for actually printing the database.  I

also tried to trap for an error using ......
on error goto PrintErrHandler  but for some reason it does not like
PrintErrHandler and it keeps changing the P, E, and H to lower case????

4) When I click on my ADD button, I can add a new Title fine if I leave
the default values in the Poster and Video field.  However, when I try
to change one of the default values, I get an error in my Add_click
event procedure.  In that procedure my code is...
datList.recordset.addnew
datList.recordset.movenext

I would really appreciate if I could get help on any or all of the above

problems.  Thank you.

Richard Alan



Thu, 24 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database

<snip>

Quote:
> 1) How can I get the form to show the total number of records upon
> startup?  I am using a label control to display the recordcount but I
> cannot get it to show the total until I hit the FORWARD button which I
> placed on the form.  I have the following code in the FORWARD button
> click_event procedure....
> lblCount.caption = datList.recordset.recordcount.   When I put this code

> in the form_load event procedure I get an error that about something not

> being set.  I do not now how to use a set command.

The recordset is probably not loaded yet... but "something" not being set? You'd have to
be a bit more specific on that.
As for showing the number of records, if you're using a Dynaset, you have to do a
Recordset.MoveLast and then .MoveFirst to get the actual record count (not necessary for
table-type recordsets).

Quote:
> 2) How do I show the current record number on the form at startup and
> also when I move FORWARD or BACKWARD through the records.  I cannot find

> a method for recordnumber.

There are no "record numbers" as such in a relational database. Just bookmarks. As for
showing what record you are currently positioned on, use Recordset.AbsolutePosition.

Quote:
> 3) How do I print the database?  I want the name of the database at the
> top of the page and the 3 fields listed below that, and then I want all
> the records to be printed.  Basically I want my PRINT button to do the
> same thing that happens when I select print from the FILE menu in Access

> and it prints the database.  I have placed a CommonDialog control on the

Well, you'll have to do a little coding there, because you'll have to read the individual
record(s) and then use the Printer methods to get them to paper.
For example,

rs.MoveFirst

Do while not rs.EOF

        Printer.Print rs!Field1 & vbTab & rs!Field2 & vbTab & rs!Field3 ... etc.
        rs.MoveNext

Loop

Printer.EndDoc

This is very crude... but it should give you the general idea.

Quote:
> form and named it dlgCommon.  I would like the print setup dialog box to

> appear first.  I entered the code dlgCommon.showprinter and that did
> that but I do not know the coding for actually printing the database.  I

> also tried to trap for an error using ......
> on error goto PrintErrHandler  but for some reason it does not like
> PrintErrHandler and it keeps changing the P, E, and H to lower case????

If you define a label as "THIS_Label" and then actually place the label in the code that
reads "this_LABEL", VB will change the case of the first occurrence, and vice-versa. This
is really just aesthetic. It will not affect how the label behave, because they are
case-insensitive.

Quote:
> 4) When I click on my ADD button, I can add a new Title fine if I leave
> the default values in the Poster and Video field.  However, when I try
> to change one of the default values, I get an error in my Add_click
> event procedure.  In that procedure my code is...
> datList.recordset.addnew
> datList.recordset.movenext

Remove the MoveNext... and add an Update right after you do the field assignments.
Changes to a recordset are not reflected back to the table(s) until you use the Update
method after AddNew or Edit.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.

Regards,

Klaus H. Probst, MCP


       ICQ: 22454937
~~~~~~~~~~~~~~~~~~~~~~~~~~~



Thu, 24 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database
Richard:

Being new to VB myself I propose you check carefully what Im saying since
Ive studied it all this month as well.
(and having some other question as well as Ill post right after...)
but - as for No 1:
What I did is - When the form load i move to the recordset.bof this (for
some unknown reason to me enables me) to show the recordcount)

2: To show the current record I use recordset.absoluteposition

as for 3 - dont have a clue :)

and as for 4: If thats all your code, U have done nothing.
To my opinion it should be something like that:
with data.recordset
.addnew
.fields(0)="a" (whatever)
.fields(1)="b" (whatever)
.fields(2)="b" (whatever)
.update
end with
data.refresh

that what i do to add new records.

Yours- Yossi

Quote:

>I am a newbie to VB.  I am trying to manipulate an Access database
>through a VB5 application.  I have a few questions and would appreciate
>any help I could get.

>Here is a little bit of background on the database.  The file is called
>collections.mdb and consists of 3 fields.  Those being Title, Poster,
>and Video.  The Title field is the index field.  I have default values
>of "OS" being placed in the Poster field and "VHS" being placed in the
>Video field.  I have the Validation text and Validation rule completed
>only to allow an acceptable value.

>Here is a little bit of background on the application.  I am linking to
>the database with a data control which I named datList.  I have my own
>buttons on the form for ADD, DELETE, FIND, FORWARD,  PRINT and BACKWARD
>because I do not like the data control and I am making that invisible to

>the user.

>1) How can I get the form to show the total number of records upon
>startup?  I am using a label control to display the recordcount but I
>cannot get it to show the total until I hit the FORWARD button which I
>placed on the form.  I have the following code in the FORWARD button
>click_event procedure....
>lblCount.caption = datList.recordset.recordcount.   When I put this code

>in the form_load event procedure I get an error that about something not

>being set.  I do not now how to use a set command.

>2) How do I show the current record number on the form at startup and
>also when I move FORWARD or BACKWARD through the records.  I cannot find

>a method for recordnumber.

>3) How do I print the database?  I want the name of the database at the
>top of the page and the 3 fields listed below that, and then I want all
>the records to be printed.  Basically I want my PRINT button to do the
>same thing that happens when I select print from the FILE menu in Access

>and it prints the database.  I have placed a CommonDialog control on the

>form and named it dlgCommon.  I would like the print setup dialog box to

>appear first.  I entered the code dlgCommon.showprinter and that did
>that but I do not know the coding for actually printing the database.  I

>also tried to trap for an error using ......
>on error goto PrintErrHandler  but for some reason it does not like
>PrintErrHandler and it keeps changing the P, E, and H to lower case????

>4) When I click on my ADD button, I can add a new Title fine if I leave
>the default values in the Poster and Video field.  However, when I try
>to change one of the default values, I get an error in my Add_click
>event procedure.  In that procedure my code is...
>datList.recordset.addnew
>datList.recordset.movenext

>I would really appreciate if I could get help on any or all of the above

>problems.  Thank you.

>Richard Alan



Fri, 25 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database

Quote:

> Well, you'll have to do a little coding there, because you'll have to read the individual
> record(s) and then use the Printer methods to get them to paper.
> For example,

> rs.MoveFirst

> Do while not rs.EOF

>         Printer.Print rs!Field1 & vbTab & rs!Field2 & vbTab & rs!Field3 ... etc.
>         rs.MoveNext

> Loop

> Printer.EndDoc

> This is very crude... but it should give you the general idea.

Thanks for the Help!  I have the following code in my Print event procedure...

    Private Sub mnuFilePrint_Click()
    On Error GoTo PrintErrHandler
    dlgCommon.Flags = cdlPDHidePrintToFile
    dlgCommon.CancelError = True
    dlgCommon.ShowPrinter

    With datList.Recordset
        .MoveFirst
        Do While Not .EOF
        Printer.Print !Title & vbTab & !Poster & vbTab & !Video
        .MoveNext
        Loop
    End With

    Printer.EndDoc
PrintErrHandler:
    Exit Sub
End Sub

but it is not doing what I need.   This is listing the records out but my print setup dialog
box it is not allowing me to select what pages to print and also the fields are not lined
up.  The output looks like this...

4D Man    OS    VHS
7th Voyage of Sinbad    OS    VHS
Amazing Colossal Man, The     OS    VHS
etc.

What I need is the printout to look like the report that ACCESS prints out.  I do not want to
load ACCESS everytime I need a printout.  There should be a way I could do it from this VB
application.  I need this VB application to give me the same results; margins, name, field
names, and the listing of all the records all lined up with the headings repeated on
subsequent pages.  And I need a nice font too, the font I am getting now is really tiny.
Would you know how to accomplish this?  Thanks for your help!

Rich



Fri, 25 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database

Quote:

> Well, you'll have to do a little coding there, because you'll have to read the individual
> record(s) and then use the Printer methods to get them to paper.
> For example,

> rs.MoveFirst

> Do while not rs.EOF

>         Printer.Print rs!Field1 & vbTab & rs!Field2 & vbTab & rs!Field3 ... etc.
>         rs.MoveNext

> Loop

> Printer.EndDoc

> This is very crude... but it should give you the general idea.

Thanks for the Help!  I have the following code in my Print event procedure...

    Private Sub mnuFilePrint_Click()
    On Error GoTo PrintErrHandler
    dlgCommon.Flags = cdlPDHidePrintToFile
    dlgCommon.CancelError = True
    dlgCommon.ShowPrinter

    With datList.Recordset
        .MoveFirst
        Do While Not .EOF
        Printer.Print !Title & vbTab & !Poster & vbTab & !Video
        .MoveNext
        Loop
    End With

    Printer.EndDoc
PrintErrHandler:
    Exit Sub
End Sub

but it is not doing what I need.   This is listing the records out but my print setup dialog
box it is not allowing me to select what pages to print and also the fields are not lined
up.  The output looks like this...

4D Man    OS    VHS
7th Voyage of Sinbad    OS    VHS
Amazing Colossal Man, The     OS    VHS
etc.

What I need is the printout to look like the report that ACCESS prints out.  I do not want to
load ACCESS everytime I need a printout.  There should be a way I could do it from this VB
application.  I need this VB application to give me the same results; margins, name, field
names, and the listing of all the records all lined up with the headings repeated on
subsequent pages.  And I need a nice font too, the font I am getting now is really tiny.
Would you know how to accomplish this?  Thanks for your help!

Rich



Fri, 25 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database

Quote:

> Well, you'll have to do a little coding there, because you'll have to read the individual
> record(s) and then use the Printer methods to get them to paper.
> For example,

> rs.MoveFirst

> Do while not rs.EOF

>         Printer.Print rs!Field1 & vbTab & rs!Field2 & vbTab & rs!Field3 ... etc.
>         rs.MoveNext

> Loop

> Printer.EndDoc

> This is very crude... but it should give you the general idea.

Thanks for the Help!  I have the following code in my Print event procedure...

    Private Sub mnuFilePrint_Click()
    On Error GoTo PrintErrHandler
    dlgCommon.Flags = cdlPDHidePrintToFile
    dlgCommon.CancelError = True
    dlgCommon.ShowPrinter

    With datList.Recordset
        .MoveFirst
        Do While Not .EOF
        Printer.Print !Title & vbTab & !Poster & vbTab & !Video
        .MoveNext
        Loop
    End With

    Printer.EndDoc
PrintErrHandler:
    Exit Sub
End Sub

but it is not doing what I need.   This is listing the records out but my print setup dialog
box it is not allowing me to select what pages to print and also the fields are not lined
up.  The output looks like this...

4D Man    OS    VHS
7th Voyage of Sinbad    OS    VHS
Amazing Colossal Man, The     OS    VHS
etc.

What I need is the printout to look like the report that ACCESS prints out.  I do not want to
load ACCESS everytime I need a printout.  There should be a way I could do it from this VB
application.  I need this VB application to give me the same results; margins, name, field
names, and the listing of all the records all lined up with the headings repeated on
subsequent pages.  And I need a nice font too, the font I am getting now is really tiny.
Would you know how to accomplish this?  Thanks for your help!

Rich



Fri, 25 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database

<snip>

Quote:
> but it is not doing what I need.   This is listing the records out but my print setup
dialog
> box it is not allowing me to select what pages to print and also the fields are not
lined
> up.  The output looks like this...

> 4D Man    OS    VHS
> 7th Voyage of Sinbad    OS    VHS
> Amazing Colossal Man, The     OS    VHS
> etc.

> What I need is the printout to look like the report that ACCESS prints out.  I do not
want to
> load ACCESS everytime I need a printout.  There should be a way I could do it from this
VB
> application.  I need this VB application to give me the same results; margins, name,
field
> names, and the listing of all the records all lined up with the headings repeated on
> subsequent pages.  And I need a nice font too, the font I am getting now is really
tiny.
> Would you know how to accomplish this?  Thanks for your help!

Like I said, crude. Printing *well* from VB (or any other app, for that matter) is a bit
complicated. The unaligned output in your printout is due to the fact that you need to
define "print zones" from where to start or stop a column, etc. Tabs don't work well with
proportional fonts. Ditto for the margins. You also have to calculate string widths,
handle alignment problems, ad nauseaum.

The Font is no problem, just do Printer.Font.Name, .Size. etc. and then print. You can
change the font properties an arbitrary number of times to get the effects you're looking
for.

I'd recommend taking a look at the Crystal Reports product that came with your copy of
VB. It will save you tons of time and effort, and it will handle what you're doing with
ease. Sometimes it's not efficient to re-invent the wheel. :-)

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.

Regards,

Klaus H. Probst, MCP


       ICQ: 22454937
~~~~~~~~~~~~~~~~~~~~~~~~~~~



Fri, 25 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database
Thanks.  If I created a report with Crystal Reports, could I then pust the PRINT button on my
VB application after updating the database and have it print using the format I created with
Crystal Reports, or do I have to load Crystal Reports and print the database from there?
Quote:


> <snip>

> > but it is not doing what I need.   This is listing the records out but my print setup
> dialog
> > box it is not allowing me to select what pages to print and also the fields are not
> lined
> > up.  The output looks like this...

> > 4D Man    OS    VHS
> > 7th Voyage of Sinbad    OS    VHS
> > Amazing Colossal Man, The     OS    VHS
> > etc.

> > What I need is the printout to look like the report that ACCESS prints out.  I do not
> want to
> > load ACCESS everytime I need a printout.  There should be a way I could do it from this
> VB
> > application.  I need this VB application to give me the same results; margins, name,
> field
> > names, and the listing of all the records all lined up with the headings repeated on
> > subsequent pages.  And I need a nice font too, the font I am getting now is really
> tiny.
> > Would you know how to accomplish this?  Thanks for your help!

> Like I said, crude. Printing *well* from VB (or any other app, for that matter) is a bit
> complicated. The unaligned output in your printout is due to the fact that you need to
> define "print zones" from where to start or stop a column, etc. Tabs don't work well with
> proportional fonts. Ditto for the margins. You also have to calculate string widths,
> handle alignment problems, ad nauseaum.

> The Font is no problem, just do Printer.Font.Name, .Size. etc. and then print. You can
> change the font properties an arbitrary number of times to get the effects you're looking
> for.

> I'd recommend taking a look at the Crystal Reports product that came with your copy of
> VB. It will save you tons of time and effort, and it will handle what you're doing with
> ease. Sometimes it's not efficient to re-invent the wheel. :-)

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Please post/reply to the newsgroup(s) so
> that everyone can benefit from the discussion.

> Regards,

> Klaus H. Probst, MCP


>        ICQ: 22454937
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~



Sat, 26 May 2001 03:00:00 GMT  
 Please help with VB5 application and Access 97 database
Very basically, what you do is design the report in CR, then add the CR OCX to you app,
and place it on a form. Then, set the ReportName property of the control to the path of
your report file, and use -i think- Crystal1.Action=1; which is PRINT!. Take a look at
the help for the OCX to get the exact syntax. I surmise you have CR 4.6 (which is what
shipped with VB5); methods changed into version 5 & 6 (5 being what I use).

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.

Regards,

Klaus H. Probst, MCP


       ICQ: 22454937
~~~~~~~~~~~~~~~~~~~~~~~~~~~


Quote:
> Thanks.  If I created a report with Crystal Reports, could I then pust the PRINT button
on my
> VB application after updating the database and have it print using the format I created
with
> Crystal Reports, or do I have to load Crystal Reports and print the database from
there?



> > <snip>

> > > but it is not doing what I need.   This is listing the records out but my print
setup
> > dialog
> > > box it is not allowing me to select what pages to print and also the fields are not
> > lined
> > > up.  The output looks like this...

> > > 4D Man    OS    VHS
> > > 7th Voyage of Sinbad    OS    VHS
> > > Amazing Colossal Man, The     OS    VHS
> > > etc.

> > > What I need is the printout to look like the report that ACCESS prints out.  I do
not
> > want to
> > > load ACCESS everytime I need a printout.  There should be a way I could do it from
this
> > VB
> > > application.  I need this VB application to give me the same results; margins,
name,
> > field
> > > names, and the listing of all the records all lined up with the headings repeated
on
> > > subsequent pages.  And I need a nice font too, the font I am getting now is really
> > tiny.
> > > Would you know how to accomplish this?  Thanks for your help!

> > Like I said, crude. Printing *well* from VB (or any other app, for that matter) is a
bit
> > complicated. The unaligned output in your printout is due to the fact that you need
to
> > define "print zones" from where to start or stop a column, etc. Tabs don't work well
with
> > proportional fonts. Ditto for the margins. You also have to calculate string widths,
> > handle alignment problems, ad nauseaum.

> > The Font is no problem, just do Printer.Font.Name, .Size. etc. and then print. You
can
> > change the font properties an arbitrary number of times to get the effects you're
looking
> > for.

> > I'd recommend taking a look at the Crystal Reports product that came with your copy
of
> > VB. It will save you tons of time and effort, and it will handle what you're doing
with
> > ease. Sometimes it's not efficient to re-invent the wheel. :-)

> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Please post/reply to the newsgroup(s) so
> > that everyone can benefit from the discussion.

> > Regards,

> > Klaus H. Probst, MCP


> >        ICQ: 22454937
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~



Sun, 27 May 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Please help - overflow error using Access 97 database

2. Please help - overflow error using Access 97 database

3. Help please Access 97 database

4. Please help - overflow error using Access 97 database

5. Fresh Access 97 database !! help please

6. Access 97 Database corrupts regularly (VB5 frontend) HELP!

7. Help, using an Access 97 DB without MS Access Application

8. Help, using an Access 97 DB without MS Access Application

9. Help, using an Access 97 DB without MS Access Application

10. VB5 and access 97 database on internet

11. Developing Access 97 database with VB5

12. Access 97 database and unicode in VB5

 

 
Powered by phpBB® Forum Software