简体   繁体   中英

Access 2010 Form Button Problems

I am currently at a loss for what to do in my current project. I am creating a form that will pull up a customer's data. It is possible the customer could have more than record, and I have three different distinct fields to help narrow to that exact customer. We have an ID field which would be primary key, their SSN which only relates to them, and their account # which also only relates to them. I am curious if there is a way for the form to not be populated when I start it, and either be able to type in a text box one of these 3 and have them linked to a query that will search for that record and fill the form with the data, or have it pull up a parameter box(can do, but cant get the data to populate in form view) I am not having any luck with using the command buttons, either they don't work the way I want them to, or the data gets pulled up in a datasheet, instead of my form.

I can manually filter on the ID numbers to find the record, but I'd rather make this user friendly for future users.

Also the form currently houses 95 fields of data, but they fit very comfortably in the form.

Access 2010

You can certainly have the form not populated. Create your three textboxes and a "go" button.

The code for the go button would be something like:

If Not IsNull(Me.txtID) Then
    sWhere = sWhere & " Or ID=" & Me.txtID
End If

If Not IsNull(Me.txtSSN) Then
    ''If SSN is text, you need quotes
    sWhere = sWhere & " Or SSN='" & Me.txtSSN & "'"
End If

If Not IsNull(Me.txtAccountNo) Then
    sWhere = sWhere & " Or AccountNo=" & Me.txtAccountNo
End If

sWhere = "WHERE 1=1 " & sWhere

sSQL = "SELECT Each, Field, Name FROM TableName " & sWhere

Me.RecordSource = sSQL

The above is typed, not tested, and is only one approach. You could also use comboboxes built with the wizard to select a customer on your form, you could have a previous form where you fill in a customer and open your form from that, you could just filter your form based on what is filled in and so on.

As far as I know, there are rules about storing SSNs, so you will need to be careful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM