PDA

View Full Version : سوال: انتقال کرسر به ابتدای حرف قبلی موقع جستجودر رویداد onchange



mohammadsaleh
دوشنبه 06 آبان 1398, 15:34 عصر
سلام دوستان
موقع جستجو و نمایش نتایج در سابفرم، کرسر به ابتدای حرف قبلی تایپ شده بر می گردد. در حقیقت باید کلمات را وارونه تایپ کرد تا نتایج درست بدست آید. کمک دوستان راهگشا خواهد بود

mohammadsaleh
چهارشنبه 08 آبان 1398, 10:59 صبح
سلام
اساتید گرامی برای این مشکل راه حلی دارند؟

mazoolagh
چهارشنبه 08 آبان 1398, 11:54 صبح
1- موارد غیر از مشکل رو از برنامه پیوست حذف کنین (هر فرم، ماژول یا عملیاتی که ارتباطی به پرسش نداره و مزاحم محسوب میشه)

2- تاپیک پایین رو ببینین
https://barnamenevis.org/showthread.php?557796-مشکل-با-سرچ-لحظه%E2%80%8Cای

mohammadsaleh
چهارشنبه 08 آبان 1398, 14:54 عصر
سلام
با تشکر از نمونه ای که ارسال فرموید.
در فرمی که پیوست کردم هدفم جستجوی لحظه ای با استفاده از رکوردست است نه رکوردسورس.
سوال اصلی من علت پرش کرسر و جلوگیری از تکمیل کلمه است. چرا بعد از نوشتن هر حرف کرسر به جای قرارگیری بعد از حرف به ماقبل حرف نقل مکان می کند

ASHKANLAEI
چهارشنبه 08 آبان 1398, 15:06 عصر
Me.Tsearch.SelStart = Len(Me.Tsearch.Text)

mohammadsaleh
چهارشنبه 08 آبان 1398, 16:27 عصر
تشکر
نمیدونم نمونه را تست کردید یا نه. در رویداد keyup قرار دادم. میشه عبارت رو نوشت ولی مشکل اینه که space رو قبول نمی کنه.
خواهشی که از اساتید داشتم اینه که علت بروز مشکل رو بفهمیم و بعد براش راه حل بیابیم.
اگر به جای سابفرم از لیست باکس استفاده کنیم مشکلی ایجاد نمیشه ولی این مشکل موقع استفاده از سابفرم اتفاق میفته

AbbasSediqi
دوشنبه 13 آبان 1398, 09:35 صبح
امیدوارم مشکلتون حل شده باشه

mohammadsaleh
دوشنبه 13 آبان 1398, 15:58 عصر
سلام
ممنون از بذل توجهتون
البته من میخواهم با روش ado جستجو انجام بشه و دیتا با رکوردست set بشه
بی زحمت یه نگاهی مجدد به نمونه بفرمایید

AbbasSediqi
دوشنبه 13 آبان 1398, 17:46 عصر
نمونه اصلاح شد

mohammadsaleh
دوشنبه 13 آبان 1398, 22:33 عصر
من علمنی حرفا فقد صیرنی عبدا

سلام خیلی تشکر از محبتتون

در همین راستا میخوام سئوالی بپرسم که شاید غلط باشه ولی خوب سئوال هست و انشاءالله استاد تصحیح می فرمایند. وقتی از طریق ADO اطلاعات مورد نظر واکشی می شوند در مجموعه ای به نام Recordset ریخته می شوند و برای اینکه یک شی مثل فرم یا گزارش از آن استفاده کند باید رکوردست را برای آن شی Set نمود :
Set Me.Query_subform.Form.Recordset = rst1
اما اگر بخواهیم RecordSource شی را انتخاب کنیم بی واسطه جدول و یا پرسش را به عنوان رکوردسورس انتخاب می کنیم
حال سئوالم اینجاست اگر اطلاعاتی را از سرور واکشی کردیم راهی برای تبدیل آن به RecordSource وجود دارد یا خیر. منظورم این است که به جای استفاده مستقیم از رکوردست ابتدا به نحوی آن را تبدیل به دیتای قابل استفاده به عنوان رکورد سورس نماییم و از آن بهره گیری کنیم

تشکر مجدد از بذل عنایت شما بزرگوار

AbbasSediqi
سه شنبه 14 آبان 1398, 03:31 صبح
من علمنی حرفا فقد صیرنی عبدا

سلام خیلی تشکر از محبتتون

در همین راستا میخوام سئوالی بپرسم که شاید غلط باشه ولی خوب سئوال هست و انشاءالله استاد تصحیح می فرمایند. وقتی از طریق ADO اطلاعات مورد نظر واکشی می شوند در مجموعه ای به نام Recordset ریخته می شوند و برای اینکه یک شی مثل فرم یا گزارش از آن استفاده کند باید رکوردست را برای آن شی Set نمود :
Set Me.Query_subform.Form.Recordset = rst1
اما اگر بخواهیم RecordSource شی را انتخاب کنیم بی واسطه جدول و یا پرسش را به عنوان رکوردسورس انتخاب می کنیم
حال سئوالم اینجاست اگر اطلاعاتی را از سرور واکشی کردیم راهی برای تبدیل آن به RecordSource وجود دارد یا خیر. منظورم این است که به جای استفاده مستقیم از رکوردست ابتدا به نحوی آن را تبدیل به دیتای قابل استفاده به عنوان رکورد سورس نماییم و از آن بهره گیری کنیم

تشکر مجدد از بذل عنایت شما بزرگوار





با سلام مجدد

این کاری که شما میخوایید انجام بدید تو sql وجود داره و به عنوان Temporary Tables یاد میشه


در اکسس برای اینکار باید یک دیتابیس temp برای داده ها بسازید و از اون استفاده کنید

نمونه کد قرارداده شد


Option Compare Database
Option Explicit


Public Function UpdateTempTable(Tablename As String, TableQueryOrSQL As String, _
Optional InCurrentDb As Boolean = False, _
Optional ValidMinutes As Integer = 0, _
Optional PK_Field As Variant = Null) As Boolean


Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strTempFile As String
Dim strSQL As String, strMsg As String
Dim strError As String
Dim varExtDB As Variant
Dim intMousePointer As Integer

On Error GoTo ProcError

intMousePointer = Screen.MousePointer
DoCmd.Hourglass True

'set the default return value for the function
UpdateTempTable = False


'If the table exists in the local db, then check to see how long it has been since
'the temp table was created. If more than ValidMinutes, then drop the table
strError = "Deleting existing table in currendtb"
If TableExists(Tablename) Then
If DateDiff("n", CurrentDb.TableDefs(Tablename).Properties("DateCreated"), Now()) <= ValidMinutes Then
UpdateTempTable = True
GoTo ProcExit
Else
DropTable Tablename
End If
End If

'If the temp table is supposed to be created in an external database, then make sure it exists
'Make sure the temp database exists in the same folder as the current project
If InCurrentDb = False Then
strError = "Creating the temp database"
strTempFile = CurrentProject.Path & "" _
& Left(CurrentProject.Name, InStrRev(CurrentProject.Name, ".") - 1) _
& "_Temp.accdb"
If FileExists(strTempFile) = False Then
DBEngine.CreateDatabase strTempFile, dbLangGeneral, dbVersion120
End If

'Check to see whether the table already exists in the temp.accdb file. If so, delete it
strError = "Dropping the table in the temp database"
Set db = DBEngine.OpenDatabase(strTempFile)
If TableExists(Tablename, db) = True Then
db.Execute "Drop Table [" & Tablename & "]", dbFailOnError
End If
Set db = Nothing
End If

'Define the SQL to insert the records from TableQueryOrSQL into the temp table
strSQL = "SELECT zz.* INTO [" & Tablename & "] "
If InCurrentDb = False Then
strSQL = strSQL & "IN " & Wrap(strTempFile)
End If
strSQL = strSQL & " FROM "

'If the TableQueryOrSQL contains a SELECT INTO statement, then display message and exit
'If the TableQueryOrSQL contains a SELECT statement, then wrap it in () as a subquery
'If the TableQueryOrSQL is a query or table then just insert the value of TableQueryOrSQL
'in the SQL string.
'However, if the table exists and it is a SharePoint list (database field in mSysObjects
'contains http:// or https:// then ignore) then ignore the table
If InStr(TableQueryOrSQL, "SELECT") > 0 And InStr(TableQueryOrSQL, "INTO") > 0 Then
strMsg = "Cannot pass a Maketable or Append query to this function"
MsgBox strMsg, vbOKOnly, "Invalid argument for TableQueryOrSQL"
strSQL = ""
ElseIf InStr(TableQueryOrSQL, "SELECT") = 1 And InStr(TableQueryOrSQL, "INTO") = 0 Then
strSQL = strSQL & "(" & TableQueryOrSQL & ") as zz"
ElseIf QueryExists(TableQueryOrSQL) Then
strSQL = strSQL & TableQueryOrSQL & " as zz"
ElseIf TableExists(TableQueryOrSQL) Then
varExtDB = DLookup("Database", "mSysObjects", "[Name] = " & Wrap(TableQueryOrSQL))
If InStr(Nz(varExtDB, ""), "http") Then
strMsg = "Unable to use Sharepoint list names directly because of potential " _
& "field type conflicts with earlier versions of Access. To include " _
& "as SharePoint list in this function, pass it a SELECT query that " _
& "includes the specific fields to be used from the list."
MsgBox strMsg, vbOKOnly, "Invalid argument for TableQueryorsQL"
strSQL = ""
Else
strSQL = strSQL & TableQueryOrSQL & " as zz"
End If
Else
MsgBox "Invalid syntax for the SQL string", vbOKOnly, "Invalid argument for TableQueryorsQL"
strSQL = ""
End If


'If strSQL = "" then exit the function
If strSQL = "" Then GoTo ProcExit

'Otherwise, execute the SQL to create an empty table in temp.accdb
strError = "Writing data to the temp table in the temp db"
CurrentDb.Execute strSQL, dbFailOnError

'If a primary key field was defined, then alter the structure of the table
If IsNull(PK_Field) = False Then
If InCurrentDb = True Then
Set db = CurrentDb
Else
Set db = DBEngine.OpenDatabase(strTempFile)
End If
strSQL = "ALTER TABLE [" & Tablename & "] " _
& "ALTER COLUMN [" & PK_Field & "] Long " _
& "CONSTRAINT PrimaryKey PRIMARY KEY;"
db.Execute strSQL, dbFailOnError
Set db = Nothing
End If

'If the temp table was created in an external db then link the table to the current project
If InCurrentDb = False Then
strError = "Linking table to the current database"

Set tdf = CurrentDb.CreateTableDef(Tablename)
tdf.Connect = ";DATABASE=" & strTempFile
tdf.SourceTableName = Tablename
CurrentDb.TableDefs.Append tdf
'DisplayNavPane (False)
End If
CurrentDb.TableDefs.Refresh

UpdateTempTable = True
ProcExit:
If Not db Is Nothing Then Set db = Nothing
DoCmd.Hourglass False
Screen.MousePointer = intMousePointer

Exit Function
ProcError:
MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly, "UpdateTempTable error"
Debug.Print "UpdateTempTable error", Err.Number, Err.Description
Resume ProcExit

End Function


Public Sub DropTable(Tablename As String)


If TableExists(Tablename) Then
DoCmd.DeleteObject acTable, Tablename
End If

End Sub


Public Function TableExists(Tablename As String, Optional db As DAO.Database) As Boolean


Dim intFields As Integer
Dim ReleaseDB As Boolean

On Error GoTo ProcError

'The default database is the currentdb, but if one is passed, use it
If db Is Nothing Then
Set db = CurrentDb
ReleaseDB = True
End If

'If the table exists, then the next line will determine how many fields are in the table
'If it doesn't exist, then this will raise an error
intFields = db.TableDefs(Tablename).Fields.Count
TableExists = True

ProcExit:
If ReleaseDB Then Set db = Nothing
Exit Function

ProcError:
TableExists = False
Resume ProcExit

End Function


Public Function QueryExists(QueryName As String, Optional db As DAO.Database) As Boolean


Dim intFields As Integer
Dim ReleaseDB As Boolean

On Error GoTo ProcError

'The default database is the currentdb, but if one is passed, use it
If db Is Nothing Then
Set db = CurrentDb
ReleaseDB = True
End If

'If the query exists, then the next line will determine how many fields are in the table
'If it doesn't exist, then this will raise an error
intFields = db.QueryDefs(QueryName).Fields.Count
QueryExists = True

ProcExit:
If ReleaseDB Then Set db = Nothing
Exit Function

ProcError:
QueryExists = False
Resume ProcExit

End Function


Public Function FileExists(FileName As String) As Boolean


FileExists = Len(Dir(FileName, vbNormal + vbHidden + vbSystem + vbReadOnly)) > 0

End Function


Public Function Wrap(WrapWhat As Variant, Optional WrapWith As String = """") As String



'This function is used to wrap some value with some sort of wrapping character.

'Accepts a variant and wraps that with whatever character or group of characters
'are passed in the optional WrapWith argument.

'It also replaces all values equal to the WrapWith text with duplicates of that character
'which enables wrapping a text string that contains quotes.

'If the WrapWhat value is NULL, then the function returns a empty string wrapped in quotes
'I generally use this to wrap text in quotes or date values in the #

Wrap = WrapWith & Replace(WrapWhat & "", WrapWith, WrapWith & WrapWith) & WrapWith

End Function




یا حق

mohammadsaleh
سه شنبه 14 آبان 1398, 13:10 عصر
بازم ممنون . استفاده از جدول موقت خیلی کاربردی و عالی است. سعی می کنم از آن استفاده کنم