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!

Command Buttons to Open Form New Record

Status
Not open for further replies.

corner40

Technical User
Nov 20, 2002
126
CA
Hi everyone
I have a form with two command buttons. This is what I would like them to do:

command button 1:
open the form bookings and only show the new record to be added.

command button 2:
open the form bookings and only show the record relating to the booking id that was picked.

how to do I open a form and only show this specific info.

thanks
Jeremy
 
Command button 1's Click event opens the form with no OpenArgs parameter. Command button 2's click event opens it passing the booking id as OpenArgs.

In form 'bookings', the Open event procedure checks for Me.OpenArgs = ""; if True, it sets Me.DataEntry = True, otherwise it sets it to False and sets Me.Filter to a criteria expression selecting the booking id, and sets Me.FilterOn = True.



Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
you can use the OpenArgs of the DoCmd.OpenForm action.
This code will open the form in either Data Entry mode (add new records only) or to the specified record based on the ID being passed as the OpenArgs


Private Sub Form_Load()
If Me.OpenArgs = "Add" Then
Me.DataEntry = True
Else
Me.DataEntry = False
With Me.RecordsetClone
.FindFirst "[ID] = " & Val(Me.OpenArgs)
If .NoMatch Then
MsgBox "No Matching Record for ID = " & Me.OpenArgs
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End With
End If
End Sub


to open the form for New Adds

DoCmd.OpenForm "Bookings", , , , , , "Add"

to open the form to a specified record selected from
a combobox named cboID

DoCmd.OpenForm "Bookings", , , , , , cboID

there are probably other ways to do this, but this does work.
HTH
Paul
 
To All . . . . .
Be aware:
ManySources said:
[blue][purple]OpenArgs[/purple] of the DoCmd.OpenForm method, [purple]only accepts a string![/purple] So if you want to pass numeric, two conversions are required.[/blue]
Convert [purple]OpenArgs[/purple] to string in the [blue]DoCmd.OpenForm[/blue] call:
Code:
[blue]DoCmd.OpenForm "FormName", , , , , , [purple][b]Str([/b][/purple]NumericValue[purple][b])[/b][/purple][/blue]
The back to numeric in the opened form:
Code:
[blue]Me!TextBoxName = [purple][b]Val([/b][/purple]Me.OpenArgs[purple][b])[/b][/purple][/blue]


Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top