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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a form in read and add modes on a variable

Status
Not open for further replies.

InkyRich

Technical User
Aug 2, 2006
126
GB
Hello all,
I am tearing my hair out!! - and I dont have a lot now!
I am trying simply to open a form either in Add or Read mode (in which case I want the last record entered) depending on a variable like OpenVar equalling 1 or -1 and whatever I try it always opens in Add mode. What am I doing wrong??
OpenVar is a global.

This is my code:
Code:
        Dim stDocName As String
        Dim stLinkCriteria As String
        stDocName = "FRMDayPlanner"
    
        
        If OpenVar = 1 Then 'Dates are equal
            DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
            DoCmd.GoToRecord , , acLast
                
                ElseIf OpenVar = -1 Then 'Dates not equal
                DoCmd.OpenForm stDocName, , , , acFormAdd
    
                End If

Am I using the GoToRecord in the wrong context perhaps?
Hope you boys can help before I am completely bald!
Inky

A fool and his money are soon parted - so you might as well send it to me!
 
How and where is OpenVar defined and populated ?
Anyway, you may try to replace this:
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria
with this:
DoCmd.OpenForm stDocName, acNormal, , , acFormReadOnly

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello again phv,
OpenVar is a global and is populated elsewhere. The variable is working according to Debug.
I cannot open it as ReadOnly because I need to modify the data.
Inky

A fool and his money are soon parted - so you might as well send it to me!
 
Unless I am missing something Read Mode = Read Only. If so please explain so that I may learn.
 
No bubba,
'Read' mode is my term for the opposite to Add. Perhaps I have put it badly. Perhaps I should have said View instead.
Inky


A fool and his money are soon parted - so you might as well send it to me!
 
And this ?
DoCmd.OpenForm stDocName, acNormal, , , acFormEdit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ah yes phv you may have a solution there I will give it a try.
Thanks I will let you know.
Inky

A fool and his money are soon parted - so you might as well send it to me!
 
Hi chaps,
Just to let you know that I seem to have solved the problem - but I dont know why!
I created a new form which is a copy of the original pasted all the original code in and it works. The properties are all the same.
I can only think that the form itself had an error. Never come across that before. Has anybody else?

Anyway thanks once again for your invaluable help.

Inky

A fool and his money are soon parted - so you might as well send it to me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top