Command Button Code

R

RFJ

I have a command button in one form that I use to open a second form (with
the second form opening to show the record that was open in the first form).

However, if the record in form one is not first saved then the second form
just shows a blank.

As VB coding is new to me I don't know what to add to get form 1 to save
first (I guess it is just one line of code)

Can SKS help out. The actual coding currently associated with the command
button is below. The name of the form I want to save is :

MAINFORM_Participant_Entry

TIA

Rob

<start>

MsgBox Err.Description
Resume Exit_Go_to_Data_Entry_Click

End Sub
Private Sub DataEntryButton_Click()
On Error GoTo Err_DataEntryButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MAINFORM_Data_ Entry"

stLinkCriteria = "[Org_Name]=" & "'" & Me![Org_Name] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_DataEntryButton_Click:
Exit Sub

Err_DataEntryButton_Click:
MsgBox Err.Description
Resume Exit_DataEntryButton_Click

End Sub

<end>
 
N

Nhan

there is an assistant to create a command button to save actual record.
Drag only a command button from toolbox on your form. Then add the generated
code to your code (to open the 2. form).
'code save record
---
'code to openform
----



else the code to save record is following:

RunCommand acCmdSaveRecord

or (access 2000)

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 
V

Van T. Dinh

Remember that the Record that appears on the first Form are stored in the
Form's buffer, _not_ in the Table (until you save/update it into the Table).
The second Form looks for the data in the Table, _not_ the first Form so it
won't be able to find the Record in the Table.

If you want to see the same Record in the second Form, you need to save /
update the Record into the Table.
 
V

Van T. Dinh

DoCmd.RunCommand acCmdSaveRecord

works fine in A200 and IIRC, also in A97.

The DoMenuItem actually refers to the Menu of Access version 7, i.e
Access95.

Another way to save the Record is:

Me.Dirty = False

(only in A2000 or later).
 
N

Nhan

Hi,
The DoMenuItem actually refers to the Menu of Access version 7, i.e
Access95.

this DoMenuItem command I have generated from Access 2k, it works well. I
think, the constant acMenuVer70 doesn't mean menus is access 97
(version7.0). But that is version of menubar, this version can be also the
version in access 2000. But I'm not sure, only the fact, the code is from
access 2k and it works well.

When I know the command: runcommand ..., I don't use doMenuItem anymore,
when it is posible.

Another way to save the Record is:

Me.Dirty = False

this is a new. It is good to know. Thanks. I will try it.
 
V

Van T. Dinh

Access version 7.0 is actually Access 95. Access 97 is version 8.0.

acMenuVer70 refers to the Menu version of Access 95.

When you use the CommandButton Wizard in A97, A2000 & A2002 (which has not
been updated by Microsoft), the generated code use the DoMenuItem using Menu
version used by Access 95.

Check the "Remarks" section of the Help topic on DoMenuItem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top