Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
charles101
Starting Member
16 Posts |
Posted - 2007-02-21 : 20:02:36
|
Hi all,Ive currently upgraded my Access application using the upsizing wizard to an Access.adp project. Im having trouble with some off the ADO calls in my existing Access forms which i modified to the followingIn the forms it calls the following code to populate the fields on the form when the combobox sample number is selectedPrivate Sub UpdateAfterSample() Dim rs As ADODB.Recordset 'modified too ADODBDim rs2 As ADODB.RecordsetDim rs3 As ADODB.RecordsetDim cn As ADODB.Connection Dim strSQL As StringDim strRowSource As StringDim lRecords As LongDim sampletypeSet cn = CurrentProject.Connection cmbSampleNumber.SetFocus strSQL = "Select * " & _ "FROM [sq Inbound Samples] WHERE [sq Inbound Samples].[Sample Number] " = & gstrSample 'Changed too used ADO connection 'Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot) 'Set rs = cn.Execute(strSQL, adCmdText) Set rs = cn.Execute(strSQL, dbOpenSnapshot) If (cmbSampleNumber <> "") And Not (rs.BOF And rs.EOF) Then Edit_Mode.Caption = "Edit Mode" With rs 'cmbFinishDate = Format(gfnCstrField(rs, "Finish Date"), "DD/MM/YYYY") 'cmbStockPileNumber = gfnCstrField(rs, "Stockpile Number") cmbSampleNumber = gfnCstrField(rs, "Inbound Samples.Sample Number") cmbSampleType = gfnCstrField(rs, "Sample Type") txtStartDate = Format(gfnCstrField(rs, "Start Date"), "DD/MM/YYYY") txtStartTime = Format(gfnCstrField(rs, "Start Date"), "HH:MM") txtFinishTime = Format(gfnCstrField(rs, "Finish Date"), "HH:MM") txtSampleTonnes = gfnCstrField(rs, "Sample Tonnes") txtMissedSamples = gfnCstrField(rs, "Missed Samples") txtDowntime = gfnCstrField(rs, "Sampler Downtime")End SubHere is the gfnCstrField function Public Function gfnCstrField(rs As ADODB.Recordset, sgField As String) As StringDim sgResult As StringOn Error Resume Next gfnCstrField = "" If IsNull(rs(sgField)) Then sgResult = " " Else sgResult = CStr(rs(sgField)) End If gfnCstrField = sgResultExit FunctionfnErr: ' MsgBox "Err# " & CStr(Err.Number) & " " & CStr(Err.Description), vbCritical, _ "Procedure: gfnCstrField"End FunctionI am getting an error at everyline where it the gfnCstrField function is being called too populate the forms. The error is sayingRuntime Error '-2147352567 (80020009)The Value you entered isnt valid for this field'I would say the ADODB connections are not defined correctly or im using the incorrect properties..Can someone help me with the correct way off using ADODB and what is happening here. Also where is the best place too define the CN connection method as I define this in every function and then close it afterwards.Thanks |
|
charles101
Starting Member
16 Posts |
Posted - 2007-02-22 : 17:24:47
|
Guys Ive solved it !!! however can anyone tell me the best ADO methods too use Im currently using Dim rs As ADODB.RecordsetDim cn As ADODB.ConnectionSet rs = cn.Execute(strSQL, dbOpenSnapshot)Set cn = CurrentProject.ConnectionWhere is the best place too put these declarations so it is efficiently maintained and executed...im thinking sub_formload , if i put it here where do i close the connection? |
|
|
|
|
|
|
|