Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a command button to open a form in datasheet view

Status
Not open for further replies.

spherey

Technical User
Jun 24, 2003
80
US
This is probably rather easy to do, but I don't know how to go about it.
I've set a form to open in datasheet view as the default. And it does. But when I open it using a command button from another form, it opens in single form view. Does anyone know a way to modify the following code so that the command button will open the form in datasheet view, instead of form view? (Code follows below.)

Thanks,

Spherey

Code:
Private Sub Open_Form_Click()
On Error GoTo Err_Open_Form_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Prime Form"
    
    stLinkCriteria = "[Account Manager]=" & "'" & Me![Account Manager] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_Form_Click:
    Exit Sub

Err_Open_Form_Click:
    MsgBox Err.Description
    Resume Exit_Open_Form_Click
    
End Sub
 
Spherey,

One of those commas that are thrown in the openform line says that you want the default form. Check HELP for something like 'acDataView' or the like. If I get back here later, I will have checked by then and give the answer.


Rollie E
 
Hey -

Thanks. I think we're on the right track, but I haven't hit on the solution yet. Typing 'acDataView' in the help index doesn't bring anything up at all. I also tried inserting that bit in between the various commas - and strangely enough, nothing happened at all. I would've thought that if that didn't cause the form to open in datasheet view, that it would have kept the form from opening at all. But instead, the form simply continued to open in single form view as if I hadn't made any changes at all. If you do hit on a solution, then please do let me know. I'd very much appreciate that.

Thanks,

Spherey
 
The proper integer for database is '3' and it immediately follows the form name.

After all this much work, remember my star!!! All kidding aside, it is an 'ac' variable but I have a hard time finding them too. I did a 'hunt and peck' to find it.


Rollie E
 
Brilliant!

That did it. Now it's doing exactly what I want it to do.

Thanks a lot, Rollie!

Spherey
 
remember if the tip is helpful to tip the tipster with a star
 
I always do, and I tipped both of your previous posts. Are they not showing up?
 
How could you use the same command button on a master form that toggles a subform between datasheet view and form view?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top