473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Data Passing from one form to another form

Hello, Can anyone solve my issue

Form: SB_1
Form: Add_NewRelations

I have used a VBA code in Form: SB_1 on a cmd (Button) for Data passing from one form to another form of Add_NewRelations for New Customer details are needed to update into Form: Add_NewRelations.

So that VBA code is working well. But some of exist customer details are no need to update into Form: Add_NewRelations and only allow for New Customer details.

So I have added an If statement with Dcount in the code for exist customers no need to add in the Form: Add_NewRelations. So If Statement with Dcount is didn’t working… how to correction from DCount?? When i was used Dcount function then whole VBA code is not working…

I have attached the dB file can anyone please see once VBA code and correction it.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button_Click()
  2. On Error GoTo ErrorHandler
  3. 'Me.Refresh
  4.  
  5. Dim strCriteria As String
  6. strCriteria = "CIDCustomer = '" & Trim(Trim(Me!RID) & " " & Trim(Me!RName)) & "'"
  7.  
  8.  'If DCount("*", "CIDCustomer", "RelationsQry") > 0 Then
  9.  'Cancel = True
  10.  'Else
  11.  
  12. If DCount("*", "RelationsQry", strCriteria) > 0 Then
  13. Cancel = True
  14. Else
  15.  
  16.    'If Not IsNull([Customer]) Then
  17.    'Me.Visible = False
  18.    DoCmd.OpenForm "Add_NewRelations", acNormal, , , , acWindowNormal
  19.    Forms![Add_NewRelations].Form.RID = Me.CID2
  20.    Forms![Add_NewRelations].Form.RName = Me.Customer
  21.    Forms![Add_NewRelations].Form.RType.Value = "Customer"
  22.    Forms![Add_NewRelations].Form.Address = Me.Address
  23.    Forms![Add_NewRelations].Form.TINNumber = Me.TINNumber
  24.    Forms![Add_NewRelations].Form.TownVLG = Me.TownVLG
  25.    Forms![Add_NewRelations].Form.RName.SetFocus
  26.    'Forms![Add_NewRelations].Visible = False
  27.    'DoCmd.Close
  28.  
  29. End If
  30.  
  31. ErrorHandler:
  32. End Sub

Thanks,
Sandhya.
Attached Files
File Type: zip SB1 BT.zip (813.0 KB, 62 views)
May 26 '15 #1
1 1642
zmbd
5,501 Expert Mod 4TB
Sorry your question was missed... it occasionally happens on busy posting days.

Have you found a solution to your issue or do you still require some assistance?

Just a few things that occur to me at first glance:
+ the use of the keyword "Cancel" as a variable. Cancel does not work in an "OnClick" event if that is your intent.

+ The most likely reason that your if-then conditional is not working as expected is because the dcount() is returning a result greater than zero. This would then imply that the sqlString at line 6 is not returning the condition that you expected.

To trouble shoot this, place the following code immediately following line 6:
Expand|Select|Wrap|Line Numbers
  1. debug.print "strCriteria= " & strCriteria
Run your code both for a new customer and an existing customer.
Press <ctrl><g> this will open the immediates window where the resolved string will be shown for each run. Check these for the expected result as criteria for yor Dlookup(). You might want to copy and paste the results back to this thread for a proofread, please be sure to use the [CODE/] format around the string... it is required for all script (VBA, SQL, etc...)

+ I noted that you have not declared your variables. I suspect that the option explicit isn't set. (Before Posting (VBA or SQL) Code - Section A(1) ) having this set and then performing the debug/compile will help you find a large number of errors. I can PM you my boilerplate that has links to some, imho, very useful tutorials and information for new Access developers if you would like.

+ Finally your
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Add_NewRelations", acNormal, , , , acWindowNormal
can be modified so that it opens for new record edition only as follows:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Add_NewRelations", acNormal, , ,acFormAdd , acWindowNormal
Normally I would use the open arguments to pass the values to this form; however, one can set them as you are doing in lines 19 thru 25; however, as I'm sure you'll notice, doing so creates the new record...

You might find our insights article covering Database Normalization and Table Structures. an interesting read.
Jun 27 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David | last post by:
Hi, I have a form which requires Serial Numbers to be loaded from another form. When I press a button, another form opens with a list of Serial Numbers. I have the record selectors enabled. ...
1
by: Alex.Wisnoski | last post by:
I have a data entry form with a combo box to look up an entrant's name. If the name is already in the table then it pulls up the record and that part of the form works fine. If the name isn't in...
3
by: fh1996 | last post by:
Form.Owner and Form.Parent, what's the difference between them? Form.ShowDialog() and Form.Show(), when to use which? Form.Activated(), what does it mean when saying a Form is "activated"? ...
15
by: http://www.visual-basic-data-mining.net/forum | last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2..... That means after i fill in any data in textBox1 and click Next button... It will bring me to...
0
by: ZackariyaYoosuf | last post by:
Hi guys,anyone can help me... I have to set a form's mdiparent property at run time..But I have the formname as string..how can I do it.. I tried this way .. 'Dim _form As Form =...
8
by: weird0 | last post by:
The scenario is that i have two forms, Form1( main form) and Form2 and both of them opened. Form1 has called Form2 inside of its constructor. class Form1 { const int NodeLimit=30; Node...
1
by: =?Utf-8?B?U2FpbXZw?= | last post by:
Hello Marc Gravell and Machin. Good Day. Why your not using an Instance in the form and yet your using a New Form? Im using it because I want to open a single form only. If Im using a New...
0
by: cheekangteh | last post by:
currently i am doing sms function by using window mobile standard 6. i have multiple form, up to 4 window form. and at the last form, i wish to collect all the data that already key in in previous...
2
by: Amian | last post by:
So I'll explain to you everything that I'm doing and then let you know what I need help with b/c maybe I should be doing this a different way. I am trying to create a database for all patient...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.