What is wrong with this

R

Ripper

I am using this code on an ID field in a subform to open another form with
the record opened in it.

Private Sub ZapID_Click()
strWhere = "[ZapID]=" & Me![ZapID]
DoCmd.OpenForm "frmZap-Add", , , strWhere

The form opens no problem, but the record is not in it. IT IS DRIVING ME
CRAZY!
 
R

Ripper

Here is the kicker. If I click the button once, the form opens in Add mode.
If I click the button again, while the form is still open, the record appears
in it. I am now moving from crazy to insane.
 
A

Allen Browne

Has the record already been saved before you try to load it into the other
form? Try adding:
If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then
MsgBox "Zap wot?"
Else
DoCmd.OpenForm ...

Is ZapID a Number type field? If it's a Text type, you need extra quotes:
strWhere = "[ZapID]=""" & Me![ZapID] & """"

If it is still not found, add:
Debug.Print strWhere
and see if what comes out in the Immediate window (Ctrl+G) makes sense.
 
R

Ripper

The record was already saved and is in tblZap.
The form comes right from the table.

ZapID is the primary key, autonumber, of the records in tblZap.

strWhere is giving me the correct ZapID.

It just seems like the form is opening in Add mode. I made the ZapID field
visible on the form and when the form opens the ZapID says AutoNumber, so it
seems like the code is opening the form wrong. There is no events in
frmZap-Add except for code I use to verify that all the fields are filled in.
MyVerify that I received from Albert Kallal. Other than a moveSize macro,
there is nothing else there. VERY VERY Strange.



--
Thanks As Always
Rip


Allen Browne said:
Has the record already been saved before you try to load it into the other
form? Try adding:
If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then
MsgBox "Zap wot?"
Else
DoCmd.OpenForm ...

Is ZapID a Number type field? If it's a Text type, you need extra quotes:
strWhere = "[ZapID]=""" & Me![ZapID] & """"

If it is still not found, add:
Debug.Print strWhere
and see if what comes out in the Immediate window (Ctrl+G) makes sense.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ripper said:
I am using this code on an ID field in a subform to open another form with
the record opened in it.

Private Sub ZapID_Click()
strWhere = "[ZapID]=" & Me![ZapID]
DoCmd.OpenForm "frmZap-Add", , , strWhere

The form opens no problem, but the record is not in it. IT IS DRIVING ME
CRAZY!
 
Top