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

Either Un-Doing or Not Saving a Record

Status
Not open for further replies.

Smeg77

Technical User
Oct 7, 2009
18
GB
I currently have a tab structure for a simple DB, and after a little bit of fiddling I've managed to get two of the tabs to link up in the way I want.

For example, the Main.ID is taken from Table 1 and then when Page2 (of the tab) is opened it passes the Main.ID into the Sub.ID field, allowing me to keep track of who has what.

The Problem I now seemed to have created, is that when I move from Page 1 to Page 2, it's automatically creating a new record in the table for Page 2, even if no data has been entered (it didn't do this originally).

I've tried to create a simple msgbox to try and stop this from happening, but it I have it run on Page 2 the record get's created, if I run it on Page 1, the record doen't get created but the msgbox appears twice, because of how it's set.

This is my current code:

Code:
Private Sub TabCtl0_Change()

Dim Name As String
Dim Val As String


If Me!TabCtl0 = 1 Then Form_Subfrm_Worker_Details_Entry.Form.Requery

        Subfrm_Lap_Entry!Laptop_ID.SetFocus
    If Subfrm_Lap_Entry!Laptop_ID.Text = "" Then
    Val = MsgBox("There is no corresponding Person Details! Please Create a Worker First?", vbOKOnly)
        
        Me.TabCtl0.Pages.Item(1).SetFocus
            End If
            
If Me!TabCtl0 = 2 Then

         Form_Subfrm_Lap_Entry.Form.Requery
         Subfrm_Lap_Entry!Laptop_ID = Form_Subfrm_Worker_Details_Entry![tblWorkers.ID]
         Name = Form_Subfrm_Worker_Details_Entry![tblWorkers.Forename] & " " & Form_Subfrm_Worker_Details_Entry![tblWorkers.Surname]
         Subfrm_Lap_Entry!txtName.SetFocus
         Subfrm_Lap_Entry!txtName.Text = Name
         
         

 End If
 
  

End Sub

Is there a way that I can set it so that either the message box works on Page 2 without committing a record, or to get it to either not save, or delete the blank record.

Thanks
 
I don't know why you want to copy details among tabs...

Why not just have the relevant details not part of the tab?

Secondly, any reason you are not simply using a sub-form with master and child fields set for the subform on the second tab?

 
It's been a real long time since I learnt how to use Access, so I'm just piecing things together as I go.

It's just meant to be a really simple DB, there's only two normal tables and one lookup table, and a User Access Table.

All of the Tabs I am using have a sub-form in them, the Master Child thing could work, but tbh I can't remember how to do it.

I'm old and rusty these days, and this relatively simple DB is just making my brain turn to goo.

 
Right click the sub-form contorl not part of the sub-form contents and select properties. I usually lasso or drag a box around the whole control and make sure I've got the control (the handles are there for resizing a control) before right clicking it. I think it is cool you can edit a subform in the main form but I wish there was a better way (or I knew it) to get out the sub-form control easily.

Master and child filds are listed in the properties. Put your cursor in either. A button with three dots will apper next to it, select the field(s) that link the two together. Then you shouldn't have to worry about any code if I am following everything and you move the common controls up out of the tab.
 
I was dabbling earlier and managed to find the properties bit where you can Link Child / Master fields, but no matter what I've tried I always get the same message.

You can't link an Unbound Form.

I'm not sure where I've gone wrong or what is required to make the Form Bound.
 
A bound form means it has a Recordsource or data behind it...

It may be easier to recreate the subform bound with the form wizard or you will have to set the record source for the form and each control's control source property. Really it depends on the number of controls and how much arranging you'd have to do, so I'll leave that to you to decide. If you are unsure, run through the form wizardd to see how much work it is to fix and compare that to making the other form bound.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top