Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm working on an application which I intend on protecting with Usernames & Passwords stored on a MS SQL Server. I've been trying for a number of days to get Visual Basics to compare the text entered in the two text boxes with the Username and Password on the SQL Database but I can't figure out a way to do it. The connection to the databse is already established and I'm able to manipulate the data on the Server from my Application, but I just can't figure out the code for 'comparing' the credentials.
The database that I'm connecting to is called Members_Details and the Table is called Logins. The logins table only holds two columns Name & Passkey (Username & Password.)
What I've tried so far is this:
SQL = "Select * from logins " & _
"where Name like '%" & Me.Usernametxt.Text.Trim & "%' AND Passkey LIKE Me.Passwordtxt.Text.Trim & "%'"
But I don't know where to go after that :/
Any help would be appreciated, and please not security is not an issue at the moment.
The problem is caused by the embedding of the Passwordtxt textbox value inside the sql text.
SQL = "Select * from logins " & _
"where Name like '%" & Me.Usernametxt.Text.Trim & _
"%' AND Passkey LIKE '" & Me.Passwordtxt.Text.Trim & "'"
However, also if you don't want advice on security, do a little step forward and write
SQL = "Select * from logins " & _
"where Name like #uname " & _
"AND Passkey = #pass"
Dim sqlCommand = new SqlCommand(SQL, con)
sqlCommand.Parameters.AddWithValue("#uname", "%" & Me.Usernametxt.Text.Trim & "%")
sqlCommand.Parameters.AddWithValue("#pass", Me.Passwordtxt.Text.Trim )
Using reader = cmd.ExecuteReader()
if reader.HasRows Then
' user authenticated
Also, usually, the passwords are required to be typed exactly (case sensitive) and thus not retrieved using a LIKE operator and wildcards.
The wildcard is also a bit strange for the username while it is acceptable to use the LIKE operator to allow the username to be case insensitive
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm doing a project and it's based on a previous Access project.
The DB I need to use is only accessed via the "Add-ins" tab, where I can find different buttons and tools to access the database.
For some reason I can't copy/paste or export the table to txt or excel spreadsheet, so I'm trying to find a way to manage the add-ins and access the table directly.
I can't find that table in the navigation bar (All Access Objects), so I guess this is the only way for me to find said table.
How do I reach the tables or queries defined in the add-ins tab?
Going to file->options->add-ins shows me that there are no add-ins installed
In the "Add-Ins" tab you see old custom menus, which are CommandBar objects.
There is no table for them, the following function lists all custom menus and should get you started.
Output is in the Immediate Window (Ctrl+G).
Public Function ListCustomCommandBars()
Dim cbarMenu As CommandBar
Dim Oberpunkt As CommandBarControl
Dim Unterpunkt As CommandBarControl
' ignore errors, e.g. menu items having no .OnAction property
On Error Resume Next
For Each cbarMenu In CommandBars
If Not cbarMenu.BuiltIn Then
Debug.Print vbCrLf & "=== " & cbarMenu.Name & " ===" & vbCrLf
For Each Oberpunkt In cbarMenu.Controls
Debug.Print Oberpunkt.Index & " " & IIf(Not Oberpunkt.Visible, "(--) ", "") & Oberpunkt.Caption
For Each Unterpunkt In Oberpunkt.Controls
Debug.Print , Unterpunkt.Index & " " & IIf(Not Unterpunkt.Visible, "(--) ", "") & Unterpunkt.OnAction, Unterpunkt.Caption
Next
Next
End If
Next
End Function
The most interesting part is .OnAction - it shows what a menu item does.
This question already has answers here:
MS Access Too Many fields during UPDATE
(2 answers)
Closed 5 years ago.
I am trying to update all rows of a table after importing data from excel to access with this code:
enter code here
DoCmd.RunSQL "UPDATE ([tbl1] INNER JOIN [2] ON " _
& "[tbl1].[Nr]= [tbl2].[Nr]) " _
& "INNER JOIN [tblExcelImport] " _
& "ON [tbl1].[Nr] = [tblExcelImport].[Nr] " _
& "SET " & strSQL & " " _
& "WHERE [tblExcelImport].[Type]= 'TYPE1';"
strSQL contains following string:
"[tbl1].[ColumnA]= [tblExcelImport]![ColumnA], [tbl1].[ColumnB]= [tblExcelImport]![ColumnB]" ... and much more columns.
So my question is how many columns can I put in to strSQL inside of a UPDATE query
in access VBA? I tried it with different amount of columns but I could not really conclude a strict logic in that.
next time I'll do more research in here I promise :D
Solved in the link:
MS Access Too Many fields during UPDATE
I know this is probably a simple thing I'm missing, but I'm hoping you all can help. I'm trying to add a textbox to my form that allows users to type in search criteria and have the query filter the records to only display those that qualify. The trick is I want the user to be able to type in info and have it check all the fields of the form and return records for any that are valid.
I set up a query with the fields that I want checked and I watched a few tutorials on setting criteria, but they are all working with multiple search bars. Is there a way to do it with only 1?
Like "*" Or [Forms]![Publications Page]![FilterBox] OR "*"
This is the criteria expression I wrote. It returns records just not the ones I want and doesn't seem to change after I change what is in [FilterBox]. I have 4 fields I'm running this same criteria on. All thoughts and suggestions are greatly appreciated!
Thanks!
The resulting criteria should be something like
[LastName] Like '*searchtext*' Or [FirstName] Like '*searchtext*' Or ...
So, you would have to set up a single criteria like this
Dim crit As String
crit = " Like '*" & Replace(Me!FilterBox, "'", "''") & "*' "
where the replace statement replces single (') by 2. This enables the user to enter an apostrophe in the search box.
Now you must create the whole criteria
crit = "[Field1]" & crit & "Or [Field2]" & crit & "Or [Field3]" & crit & "Or [Field4]" & crit
here is my code:
Text22 = DLookup("[Program_No]", "1_Supportive_Housing", "[Program_Name] = '" & Replace([Me.Program_Name], "'", "''") & "' And [BudgetYear] = " & [Me.BudgetYear])
I am not sure what is wrong with it, but it keeps giving me the following error:
Can't find the field | in your expression
I have been trying to get rid of this error but nothing works.
OnKeyPress, this event triggers. As the user writes, it should be able to lookup the value in the table and assign it to text22.
Looks like you want to reference to form fields [Me.Program_Name] & [Me.BudgetYear], but Access tries to find fields with exactly this name, including "Me." prefix. Try to remove brackets at all, or use Me.[Program_Name] and Me.[BudgetYear] instead.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am required to provide a way for users to choose which column they want to display from a table. The user has a combo box of column names in a form which they can select one of and then hit a button which opens a report. I wrote some code which creates an SQL query based on the user's input, but it's not being called. I've tried inserting MsgBox statements, asserts, etc., but it never gets called. If I use a macro instead, that will be run, but not this sub...
Private Sub Report_Open(Cancel As Integer)
Dim field As String
Dim sqlQuery As String
Dim ctl As Control
ctl = "Forms![RuleGroupForm]![selectRuleFieldCombo]"
field = "rules.[" & ctl & "]"
' E.g. if the field was "Source File", the final query should look like this:
'SELECT overview.ID, relationship.rulesID, rules.[Source File], overview.[Rule Group], rules.RulegroupID
'FROM (overview INNER JOIN relationship ON overview.id=relationship.id)
'INNER JOIN rules ON relationship.rulesID=rules.ID
'WHERE rules.[Source File] IS NOT NULL;
sqlQuery = "SELECT overview.ID, relationship.rulesID, " & field
sqlQuery = sqlQuery & ", overview.[Rule Group], rules.RulegroupID"
sqlQuery = sqlQuery & "FROM (overview INNER JOIN relationship ON overview.id=relationship.id) "
sqlQuery = sqlQuery & "INNER JOIN rules ON relationship.rulesID=rules.ID"
sqlQuery = sqlQuery & "WHERE " & field & " IS NOT NULL;"
Me.RecordSource = sqlQuery
Requery
debugText = "New SQL Query = " & sqlQuery
End Sub
Thanks.
Edit: Resolved, not sure how to respond to own question...
There are a few things to check, apart from close and open, when you get odd behaviour such as this in Access. One is to see if the event on the properties sheet for the form or report, Open in this case, still contains [Event Procedure] - occasionally a form or report can have the code, but the event is not marked. When developing, that is, adding forms, reports and code, it is a good idea to run Compact and Repair on a regular basis, this also means regular back-ups - a simple copy saves a lot of grief. Finally, when developing fairly regular Decompiles are a good idea. I keep a small script that I can drop the Access file on to run decompile.