Enable Save button on different tabs when a form opens

I have a tab control on a form, and a couple different tabs have save buttons on them. Once the user saves data (via SQL statements in VBA), I set the .enabled = false so that they cannot use this button again until moving to a brand new record (which is a button click on the overall form).

so when my form open i was going to reference a sub that enabled all these save buttons because the open event would mean new record. though i get an error that says it either does not exist, or is closed.

any ideas?

thanks

EDIT:

Sub Example()
error handling

Dim db as dao.database
dim rs as dao.recordset
dim sql as string

SQL = "INSERT INTO tblMain (Name, Address, CITY) VALUES ("

if not isnull (me.name) then
    sql = sql & """" & me.name & ""","
else
    sql = sql & " NULL,"
end if

if not insull(me.adress) then
    sql = sql & " """ & me.address & ""","
else
    sql = sql & " NULL,"
end if

if not isnull(me.city) then
   sql = sql & " """ & me.city & ""","
else
   sql = sql & " NULL,"
end if

'debug.print(sql)
set db = currentdb
db.execute (sql)

MsgBox "Changes were successfully saved"

me.MyTabCtl.Pages.Item("SecondPage").setfocus
me.cmdSaveInfo.enabled = false

and then on then the cmdSave needs to get re enabled on a new record (which by the way, this form is unbound), so it all happens when the form is re-opened. I tried this:

Sub Form_Open()

me.cmdSaveInfo.enabled = true

End Sub

and this is where I get the error stated above. So this is also not the tab that has focus when the form opens. Is that why I get this error? I cannot enable or disable a control when the tab is not showing?

Answers


You cannot use the form open event to manipulate controls, they have not been initiated at that stage. Use the form load event.

It should never be necessary to set focus to a tab, or even to reference it when working with a control. You will notice that controls must have names unique to the form, and adding a tab does not change this.


I suggest you set some form-level variables: booBtn_1_enabled as Boolean, booBtn_2_enabled as Boolean. Set these to T or F as needed; obviously, all T when the form is opened. Pick a form event (possibly the Current event, but preferably one that is triggered less often) that reviews these variables and sets the controls accordingly:

Me.btnBtn_1.Enabled = booBtn_1_enabled 
Me.Repaint

Something like that, but obviously Me.btnBtn_1 may need a more complicated reference.


Need Your Help

AS3 load variables from a txt file which has && formatting

actionscript-3 flash variables

I'm trying to load a txt file of variables into my AS3 project. The problem I have though seems to be down to the fact that the txt file (which is pre formatted and cannot be changed) is formatted ...

Translating a SELECT / IN SQL query to cake find

cakephp

I have a query along the lines of this: