Saving open form from a different form

niak32

Registered User.
Local time
Today, 14:55
Joined
Nov 1, 2008
Messages
28
This might be a really simple thing to do but for some reason i can not do it.

I have 2 forms, the main one has a bunch of labels used as buttons with a text box behind them, depending on what number is in the text box, the back ground color of the label \ button is changed accordingly.

I have a second form which controls the caption of these... (I'm just going to call them buttons even know they are labels, will make things easier to understand I hope (more for me than you) ) buttons. when the second form changes the caption of these buttons, I set all the colors back to default in the VBA code then I am trying to save the form while open (the form open in the background) and then run the code to reapply the colors.

The only thing that does not work is saving the form in the back ground. Name change is ok, color reset works, then applying the new colors works.

the code does not error unless i step it through. When i close my database and reopen it, the caption is back to what it was before.

The reason I want to save it is of course to keep the new caption but not keep the color that may be applied to the button before hand. Code below

Code:
Private Sub cmdApply_Click()
Select Case Me.txtStationID

Case 21
Forms![frm_main]![cmdLifeguard01].Caption = Me.txtStationName
Case Else
GoTo skip
End Select

Dim strBackColor As String

strBackColor = "-2147483633"

Forms![frm_main]![cmdStation1].BackColor = strBackColor


'DoCmd.Save acForm, frm_main

Dim strForm As String
strForm = "frm_main"
DoCmd.Save acForm, strForm


'Call Forms(frm_main).Save

Call Forms(frm_main).refreshbuttons

skip:


End Sub
lots of the select case code cut out to make things more readable

EDIT: Also tried making a button on the main form to close the form and reopen it, saving the form i thought, didn't work eithre

Code:
DoCmd.Close acForm, "frm_main", acSaveYes
DoCmd.OpenForm "frm_main", acNormal
 
Last edited:
Ok, looks like I have solved my problem, turns out that I couldn't save the form anyway after changing the label caption. So I changed the method:

Close the main form
open main form in design view
change the labels caption
change all colors to default
close the main form saving changed
open the main form in normal view
main form on open \ on load changes the colors for me

Code:
Private Sub cmdApply_Click()

DoCmd.Close acForm, "frm_main", acSaveNo
DoCmd.OpenForm "frm_main", acDesign

Select Case Me.txtStationID

Case 21
Forms![frm_main]![cmdLifeguard01].Caption = Me.txtStationName
Case 40
Forms![frm_main]![cmdLifeguard20].Caption = Me.txtStationName
Case Else
GoTo skip
End Select

Dim strBackColor As String

strBackColor = "-2147483633"

Forms![frm_main]![cmdStation1].BackColor = strBackColor

DoCmd.Close acForm, "frm_main", acSaveYes
DoCmd.OpenForm "frm_main", acNormal
skip:


End Sub

Perhaps I didn't need to ask on the forums but since I did, I hope someone else can learn from this as well.
 

Users who are viewing this thread

Back
Top Bottom