客户数据库 - 创建新客户 - 一个表单链接到另一个表单 [英] Customer Database - Creating New Customer - One form linked into another

查看:96
本文介绍了客户数据库 - 创建新客户 - 一个表单链接到另一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我希望有人可以帮助我。


 


我正在创建一个数据库,其中包含我公司合作的商家信息。


 


这个想法是最终用户可以点击按钮添加新的总线iness然后点击"下一步"按钮添加该业务的联系人姓名和
详细信息。


 


其表格设置如下,


 


BusinessesTBL


主键 -
BusinessID


商家名称


行业


扇区



CustomerTBL


外键 - BusinessID
(与BusinessesTBL相关)


主键 -
CustomerID


客户名称


(更多客户明细字段)


 


 


然后我为这两个表创建了一个链接表单。


 


导航看起来像这样,



主菜单>


按钮"CreateNewContact">


表格1打开>


输入新业务信息(BusinessesTBL)>


按钮"下一步">


打开表单2并将"BusinessID"复制到Form2>


为新联系人输入信息(CustomerTBL)>


按钮"保存并关闭"


 


当我关闭填写所有信息的表单时,我会收到以下错误信息...


 


"您无法添加或更改记录,因为表格中需要相关记录"


 



 


如何使这项工作?


我输入代码的代码是什么?


 


这是目前为两种表格编写的VBA。




FORM 1

选项比较数据库
Sub Form_Current()
On Error GoTo Form_Current_Err
如果ChildFormIsOpen()那么FilterChildForm
Form_Current_Exit:
退出Sub
Form_Current_Err:
MsgBox错误$
恢复Form_Current_Exit
结束Sub
Sub ToggleLink_Click( )
On Error GoTo ToggleLink_Click_Err
If ChildFormIsOpen()Then
CloseChildForm
Else
OpenChildForm
FilterChildForm
End if
ToggleLink_Click_Exit:
退出Sub
ToggleLink_Click_Err:
MsgBox错误$
恢复ToggleLink_Click_Exit
结束Sub
Private Sub FilterChildForm()
如果Me.NewRecord则
Forms![CysylltiadauBusnes] .DataEntry = True
Forms![CysylltiadauBusnes]![BusnesID] = Me![BusnesID]
Else
Forms![CysylltiadauBusnes] .Filter =" [BusnesID] ="& Me。[BusnesID]
Forms![CysylltiadauBusnes] .FilterOn = True
End if
End Sub
Private Sub OpenChildForm()
DoCmd.OpenForm" CysylltiadauBusnes"
如果不是我。[ToggleLink]那么我![ToggleLink] = True
End Sub
Private Sub CloseChildForm()
DoCmd.Close acForm,"CysylltiadauBusnes""
如果我![ToggleLink]那么我![ToggleLink] = False
End Sub
私人函数ChildFormIsOpen()
ChildFormIsOpen =(SysCmd(acSysCmdGetObjectState,acForm," CysylltiadauBusnes" )和acObjStateOpen)<>假
结束函数

私有子ToggleLink_MouseDown(按钮为整数,按整数换算,X为单,Y为单)
结束子



FORM 2


选项比较数据库
Sub Form_Load()
错误GoTo Form_Load_Err
如果ParentFormIsOpen()Then Forms![EnwBusnes]!ToggleLink = True
Form_Load_Exit:
退出Sub
Form_Load_Err:
MsgBox错误$
恢复Form_Load_Exit
结束Sub
Sub Form_Unload(取消为整数)
出错时GoTo Form_Unload_Err
如果是ParentFormIsOpen()那么表格![EnwBusnes]!ToggleLink = False
Form_Unload_Exit:
退出Sub
Form_Unload_Err:
MsgBox错误$
恢复Form_Unload_Exit
结束Sub
Privat e函数ParentFormIsOpen()
ParentFormIsOpen =(SysCmd(acSysCmdGetObjectState,acForm," EnwBusnes")和acObjStateOpen)<>假
结束函数

任何有关此的帮助将不胜感激!



谢谢,



Rhys。


 

解决方案

嗨Rhys,


你在说什么当你说"New Contact?"时新联系人是企业还是个人?在我看来,我想象一个"客户"。可以是企业还是个人,对吗?如果是这样,您是否尝试为每个
业务添加联系人点?如果是这样,我建议考虑使用表单/子表单设置,这样您就不必担心在两个表单之间传递数据。


只需要我的2美分......


Hello,

I hope someone can help me.

 

I am creating a database which holds info of Businesses that my company work with.

 

The idea is that the end user can click a button to add a new Business and then click the "next" button to add the contact name and details for that business.

 

The tables for that are set up like so,

 

BusinessesTBL

Primary Key - BusinessID

Business Name

Industry

Sector

CustomerTBL

Foreign Key - BusinessID (Related to BusinessesTBL)

Primary Key - CustomerID

CustomerName

(More Customer Detail Fields)

 

 

I’ve then created a Linked Form for the two Tables.

 

The navigation looks like so,

Main Menu >

Button "CreateNewContact" >

Form 1 Opens >

Enter Info for new Business (BusinessesTBL) >

Button "Next" >

Opens Form 2 and copies "BusinessID" onto Form2 >

Enter Info for new Contact (CustomerTBL) >

Button "Save&Close"

 

When I go to close that Form with all the info filled in I get the following Error Message ...

 

"You cannot add or change a record because a related record is required in table"

 

The reason I’m getting this is because the "BusinessesTBL" table isn’t being updated between the action of going from one form to the other.

 

How do I make this work?

What code and where do I enter the code for this to be done?

 

Here is the VBA that is currently written for both forms.

FORM 1

Option Compare Database
Sub Form_Current()
On Error GoTo Form_Current_Err
    If ChildFormIsOpen() Then FilterChildForm
Form_Current_Exit:
    Exit Sub
Form_Current_Err:
    MsgBox Error$
    Resume Form_Current_Exit
End Sub
Sub ToggleLink_Click()
On Error GoTo ToggleLink_Click_Err
    If ChildFormIsOpen() Then
        CloseChildForm
    Else
        OpenChildForm
        FilterChildForm
    End If
ToggleLink_Click_Exit:
    Exit Sub
ToggleLink_Click_Err:
    MsgBox Error$
    Resume ToggleLink_Click_Exit
End Sub
Private Sub FilterChildForm()
    If Me.NewRecord Then
        Forms![CysylltiadauBusnes].DataEntry = True
        Forms![CysylltiadauBusnes]![BusnesID] = Me![BusnesID]
    Else
        Forms![CysylltiadauBusnes].Filter = "[BusnesID] = " & Me.[BusnesID]
        Forms![CysylltiadauBusnes].FilterOn = True
    End If
End Sub
Private Sub OpenChildForm()
    DoCmd.OpenForm "CysylltiadauBusnes"
    If Not Me.[ToggleLink] Then Me![ToggleLink] = True
End Sub
Private Sub CloseChildForm()
    DoCmd.Close acForm, "CysylltiadauBusnes"
    If Me![ToggleLink] Then Me![ToggleLink] = False
End Sub
Private Function ChildFormIsOpen()
    ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "CysylltiadauBusnes") And acObjStateOpen) <> False
End Function

Private Sub ToggleLink_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
End Sub

FORM 2

Option Compare Database
Sub Form_Load()
On Error GoTo Form_Load_Err
    If ParentFormIsOpen() Then Forms![EnwBusnes]!ToggleLink = True
Form_Load_Exit:
    Exit Sub
Form_Load_Err:
    MsgBox Error$
    Resume Form_Load_Exit
End Sub
Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
    If ParentFormIsOpen() Then Forms![EnwBusnes]!ToggleLink = False
Form_Unload_Exit:
    Exit Sub
Form_Unload_Err:
    MsgBox Error$
    Resume Form_Unload_Exit
End Sub
Private Function ParentFormIsOpen()
    ParentFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "EnwBusnes") And acObjStateOpen) <> False
End Function

Any help with this would be greatly appreciated!

Thanks,

Rhys.

 

解决方案

Hi Rhys,

What are you referring to when you say "New Contact?" Is the new contact a business or a person? I imagine, in your case, a "customer" can be either a business or a person, correct? If so, are you trying to add point of contacts for each business? If so, I would recommend consider using a form/subform setup, so you won't have to worry about passing data between two forms.

Just my 2 cents...


这篇关于客户数据库 - 创建新客户 - 一个表单链接到另一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆