Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2007, 04:21 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default Passing value to subform using SQL

Hi All

This works fine with Access Db but having problem when connection with SQL db

I've two forms
Callsheet
Callsheet subform

Selecting a value form Combobox [RepList] 'Sales representative list is populating list box [NearCustomer]

List Box: Near Customer Properties
Name: NearCustomers
Row Source Type:Table/View/StoredProc
Row Source: CustomerLocationList [stored proc]

Now when click on any list box Item run this piece of code

Private Sub NearCustomers_DblClick(Cancel As Integer)
Dim r As New ADODB.Recordset '[ok]
On Error GoTo nc_err'[ok]

r.Open "CallSheet", CurrentProject.Connection, adOpenKeyset, adLockOptimistic'[ok]
r.AddNew'[ok]
r!CID = Me!NearCustomers'[ok]
r!Rep = RepList'[ok]
r!TDate = Date'[ok]
r!ApptTime = #12:00:00 AM#'[ok]
r!User = CUser()'[ok]
r!SDate = Now()'[ok]
r.Update'[ok]
r.Close'[ok]

Me!CallSub.Requery [Error here code in next sub]

nc_exit:'[ok]
    Exit Sub'[ok]
nc_err:'[ok]
    e Err.number, Err.Description'[ok]
    Resume nc_exit'[ok]
End Sub'[ok]

Private Sub Form_Current()
Dim r As New ADODB.Recordset, criteria As String
On Error Resume Next

If IsNull(Me!CID) Then Exit Sub [it doesnt have any value here Me!CID is null but same piece of code with Access db work fine here]

r.Open "SELECT APC FROM Customers WHERE CID='" & Me!CID & "'", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
If Not r.EOF Then
    If IsNull(r!APC) Or Len(r!APC) < 2 Then
        Me.Parent.PostcodeSearch = Null
    Else
        Me.Parent.PostcodeSearch = Left$(r!APC, 2)
    End If
    Me.Parent.AddrSearch = Null
    Me.Parent.NearCustomers.Requery
End If
r.Close

flag = False

End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
Access VBA passing to subform ayazhoda Access VBA 1 July 11th, 2007 07:45 AM
access adp subform connected to sql 2005 skype Access 1 February 5th, 2007 08:45 AM
Sql Server Parameter Passing ctranjith SQL Language 4 October 8th, 2004 12:35 AM
Passing a Variable to a SubForm in Access ritag Access 1 September 29th, 2004 03:53 PM
Filter Subform B Based on Field in Subform A SerranoG Access VBA 3 June 18th, 2004 12:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.